• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  *
17  */
18 package android.healthconnect.cts.ui.widget
19 
20 import android.app.DatePickerDialog
21 import android.app.DatePickerDialog.OnDateSetListener
22 import android.content.DialogInterface
23 import android.healthconnect.cts.ui.HealthConnectBaseTest
24 import androidx.test.annotation.UiThreadTest
25 import com.google.common.truth.Truth.assertThat
26 import org.junit.Test
27 import org.mockito.ArgumentMatchers.any
28 import org.mockito.ArgumentMatchers.eq
29 import org.mockito.Mockito.atLeast
30 import org.mockito.Mockito.mock
31 import org.mockito.kotlin.verify
32 
33 class DatePickerDialogTest : HealthConnectBaseTest() {
34 
35     @Test
36     @UiThreadTest
testConstructornull37     fun testConstructor() {
38         val datePickerDialog = DatePickerDialog(context)
39         assertThat(datePickerDialog.datePicker).isNotNull()
40     }
41 
42     @Test
43     @UiThreadTest
testUpdateDate_shouldUpdateTheListenerPassedIntonull44     fun testUpdateDate_shouldUpdateTheListenerPassedInto() {
45         val mockCallBack: OnDateSetListener = mock(OnDateSetListener::class.java)
46         val datePickerDialog = DatePickerDialog(context)
47         datePickerDialog.setOnDateSetListener(mockCallBack)
48 
49         datePickerDialog.updateDate(/* year= */ 2019, /* month= */ 1, /* dayOfMonth= */ 1)
50         datePickerDialog.onClick(datePickerDialog, DialogInterface.BUTTON_POSITIVE)
51 
52         verify(mockCallBack, atLeast(1)).onDateSet(any(), eq(2019), eq(1), eq(1))
53     }
54 }
55