Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2015 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  *      http://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 package android.widget.cts;
     18 
     19 import static org.junit.Assert.assertFalse;
     20 import static org.junit.Assert.assertTrue;
     21 
     22 import android.app.Activity;
     23 import android.app.AlertDialog;
     24 import android.app.DatePickerDialog;
     25 
     26 import androidx.test.annotation.UiThreadTest;
     27 import androidx.test.filters.MediumTest;
     28 import androidx.test.rule.ActivityTestRule;
     29 import androidx.test.runner.AndroidJUnit4;
     30 
     31 import org.junit.Before;
     32 import org.junit.Rule;
     33 import org.junit.Test;
     34 import org.junit.runner.RunWith;
     35 
     36 /**
     37  * Test {@link DatePickerDialog}.
     38  */
     39 @MediumTest
     40 @RunWith(AndroidJUnit4.class)
     41 public class DatePickerDialogTest {
     42     private Activity mActivity;
     43 
     44     @Rule
     45     public ActivityTestRule<DatePickerDialogCtsActivity> mActivityRule =
     46             new ActivityTestRule<>(DatePickerDialogCtsActivity.class);
     47 
     48     @Before
     49     public void setup() {
     50         mActivity = mActivityRule.getActivity();
     51     }
     52 
     53     @UiThreadTest
     54     @Test
     55     public void testConstructor() {
     56         new DatePickerDialog(mActivity, null, 1970, 1, 1);
     57 
     58         new DatePickerDialog(mActivity, AlertDialog.THEME_TRADITIONAL, null, 1970, 1, 1);
     59 
     60         new DatePickerDialog(mActivity, AlertDialog.THEME_HOLO_DARK, null, 1970, 1, 1);
     61 
     62         new DatePickerDialog(mActivity,
     63                 android.R.style.Theme_Material_Dialog_Alert, null, 1970, 1, 1);
     64     }
     65 
     66     @UiThreadTest
     67     @Test(expected=NullPointerException.class)
     68     public void testConstructorWithNullContext() {
     69         new DatePickerDialog(null, null, 1970, 1, 1);
     70     }
     71 
     72     @UiThreadTest
     73     @Test
     74     public void testShowDismiss() {
     75         final DatePickerDialog datePickerDialog = new DatePickerDialog(mActivity, null, 1970, 1, 1);
     76 
     77         datePickerDialog.show();
     78         assertTrue("Showing date picker", datePickerDialog.isShowing());
     79 
     80         datePickerDialog.show();
     81         assertTrue("Date picker still showing", datePickerDialog.isShowing());
     82 
     83         datePickerDialog.dismiss();
     84         assertFalse("Dismissed date picker", datePickerDialog.isShowing());
     85 
     86         datePickerDialog.dismiss();
     87         assertFalse("Date picker still dismissed", datePickerDialog.isShowing());
     88     }
     89 }
     90