1 /* 2 * Copyright (C) 2019 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 com.android.settings.display; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.mockito.Mockito.doReturn; 22 import static org.mockito.Mockito.spy; 23 import static org.mockito.Mockito.times; 24 import static org.mockito.Mockito.verify; 25 26 import android.content.Context; 27 import android.content.DialogInterface; 28 import android.content.SharedPreferences; 29 import android.provider.Settings; 30 31 import org.junit.Before; 32 import org.junit.Test; 33 import org.junit.runner.RunWith; 34 import org.mockito.Mock; 35 import org.mockito.MockitoAnnotations; 36 import org.robolectric.RobolectricTestRunner; 37 import org.robolectric.RuntimeEnvironment; 38 39 @RunWith(RobolectricTestRunner.class) 40 public class DarkUIInfoDialogFragmentTest { 41 private DarkUIInfoDialogFragment mFragment; 42 @Mock 43 private DialogInterface dialog; 44 45 46 @Before setup()47 public void setup() { 48 MockitoAnnotations.initMocks(this); 49 mFragment = spy(new DarkUIInfoDialogFragment()); 50 } 51 52 @Test dialogDismissedOnConfirmation()53 public void dialogDismissedOnConfirmation() { 54 doReturn(RuntimeEnvironment.application).when(mFragment).getContext(); 55 SharedPreferences prefs = RuntimeEnvironment.application.getSharedPreferences( 56 DarkUIPreferenceController.DARK_MODE_PREFS, 57 Context.MODE_PRIVATE); 58 assertThat(prefs.getBoolean(DarkUIPreferenceController.PREF_DARK_MODE_DIALOG_SEEN, false)) 59 .isFalse(); 60 mFragment.onClick(dialog, DialogInterface.BUTTON_POSITIVE); 61 verify(dialog, times(1)).dismiss(); 62 assertThat(Settings.Secure.getInt(RuntimeEnvironment.application.getContentResolver(), 63 Settings.Secure.DARK_MODE_DIALOG_SEEN, -1)).isEqualTo(1); 64 } 65 } 66