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 androidx.appcompat.app; 18 19 import static org.junit.Assert.assertNotNull; 20 import static org.junit.Assert.assertTrue; 21 22 import android.app.Dialog; 23 import android.os.Bundle; 24 import android.support.test.InstrumentationRegistry; 25 import android.support.test.filters.MediumTest; 26 import android.support.test.rule.ActivityTestRule; 27 import android.support.test.runner.AndroidJUnit4; 28 29 import org.junit.Rule; 30 import org.junit.Test; 31 import org.junit.runner.RunWith; 32 33 @MediumTest 34 @RunWith(AndroidJUnit4.class) 35 public class DialogTestCase { 36 @Rule 37 public final ActivityTestRule<WindowDecorAppCompatActivity> mActivityTestRule = 38 new ActivityTestRule<>(WindowDecorAppCompatActivity.class); 39 40 @Test 41 public void testDialogFragmentShows() { 42 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); 43 44 TestDialogFragment fragment = new TestDialogFragment(); 45 fragment.show(mActivityTestRule.getActivity().getSupportFragmentManager(), null); 46 47 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); 48 49 assertNotNull("Dialog was null", fragment.getDialog()); 50 assertTrue("Dialog was not being shown", fragment.getDialog().isShowing()); 51 } 52 53 public static class TestDialogFragment extends AppCompatDialogFragment { 54 @Override 55 public Dialog onCreateDialog(Bundle savedInstanceState) { 56 return new AlertDialog.Builder(getContext()) 57 .setTitle("Test") 58 .setMessage("Message") 59 .setPositiveButton("Button", null) 60 .create(); 61 } 62 } 63 } 64 65