1 /* 2 * Copyright (C) 2018 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 package com.android.settings; 17 18 import static com.google.common.truth.Truth.assertThat; 19 20 import static org.mockito.ArgumentMatchers.isNull; 21 import static org.mockito.Mockito.doReturn; 22 import static org.mockito.Mockito.times; 23 import static org.mockito.Mockito.verify; 24 25 import android.app.Activity; 26 import android.app.AlertDialog; 27 28 import com.android.settings.testutils.SettingsRobolectricTestRunner; 29 30 import org.junit.Before; 31 import org.junit.Test; 32 import org.junit.runner.RunWith; 33 import org.mockito.Mock; 34 import org.mockito.MockitoAnnotations; 35 36 @RunWith(SettingsRobolectricTestRunner.class) 37 public class RestrictedSettingsFragmentTest { 38 39 @Mock 40 private AlertDialog mAlertDialog; 41 private RestrictedSettingsFragment mFragment; 42 43 @Before setUp()44 public void setUp() { 45 MockitoAnnotations.initMocks(this); 46 } 47 48 @Test onActivityResult_dismissesDialogOnOk()49 public void onActivityResult_dismissesDialogOnOk() { 50 mFragment = new RestrictedSettingsFragment("fake_key") { 51 @Override 52 public int getMetricsCategory() { 53 return 0; 54 } 55 }; 56 doReturn(true).when(mAlertDialog).isShowing(); 57 mFragment.mActionDisabledDialog = mAlertDialog; 58 mFragment.onActivityResult(RestrictedSettingsFragment.REQUEST_PIN_CHALLENGE, 59 Activity.RESULT_OK, 60 null); 61 62 // dialog should be gone 63 verify(mAlertDialog, times(1)).setOnDismissListener(isNull()); 64 verify(mAlertDialog, times(1)).dismiss(); 65 } 66 } 67