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 24 import android.content.Context; 25 26 import com.android.settings.display.darkmode.DarkModePreference; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.MockitoAnnotations; 32 import org.robolectric.RobolectricTestRunner; 33 import org.robolectric.RuntimeEnvironment; 34 35 @RunWith(RobolectricTestRunner.class) 36 public class DarkUIPreferenceControllerTest { 37 38 private DarkUIPreferenceController mController; 39 private Context mContext; 40 41 @Before setUp()42 public void setUp() { 43 MockitoAnnotations.initMocks(this); 44 mContext = spy(RuntimeEnvironment.application); 45 mController = spy(new DarkUIPreferenceController(mContext, "dark_ui_mode")); 46 mController.mPreference = new DarkModePreference(mContext, null /* AttributeSet attrs */); 47 mController.onStart(); 48 } 49 50 @Test batterySaverToggles_disabledStateUpdates()51 public void batterySaverToggles_disabledStateUpdates() { 52 doReturn(true).when(mController).isPowerSaveMode(); 53 mController.updateEnabledStateIfNeeded(); 54 assertThat(mController.mPreference.isEnabled()).isFalse(); 55 56 doReturn(false).when(mController).isPowerSaveMode(); 57 mController.updateEnabledStateIfNeeded(); 58 assertThat(mController.mPreference.isEnabled()).isTrue(); 59 60 doReturn(true).when(mController).isPowerSaveMode(); 61 mController.updateEnabledStateIfNeeded(); 62 assertThat(mController.mPreference.isEnabled()).isFalse(); 63 } 64 } 65