1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 
15 package com.android.settings.display;
16 
17 import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
18 import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
19 
20 import static com.google.common.truth.Truth.assertThat;
21 
22 import com.android.settings.testutils.shadow.SettingsShadowResources;
23 
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.robolectric.RobolectricTestRunner;
29 import org.robolectric.RuntimeEnvironment;
30 import org.robolectric.annotation.Config;
31 
32 @RunWith(RobolectricTestRunner.class)
33 @Config(shadows = SettingsShadowResources.class)
34 public class NightDisplayFooterPreferenceControllerTest {
35 
36     private NightDisplayFooterPreferenceController mController;
37 
38     @Before
setUp()39     public void setUp() {
40         mController =
41                 new NightDisplayFooterPreferenceController(RuntimeEnvironment.application, "key");
42     }
43 
44     @After
tearDown()45     public void tearDown() {
46         SettingsShadowResources.reset();
47     }
48 
49     @Test
getAvailabilityStatus_configuredAvailable_shouldReturnAVAILABLE_UNSEARCHABLE()50     public void getAvailabilityStatus_configuredAvailable_shouldReturnAVAILABLE_UNSEARCHABLE() {
51         SettingsShadowResources.overrideResource(
52                 com.android.internal.R.bool.config_nightDisplayAvailable, true);
53 
54         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
55     }
56 
57     @Test
getAvailabilityStatus_configuredUnavailable_shouldReturnUNSUPPORTED_ON_DEVICE()58     public void getAvailabilityStatus_configuredUnavailable_shouldReturnUNSUPPORTED_ON_DEVICE() {
59         SettingsShadowResources.overrideResource(
60                 com.android.internal.R.bool.config_nightDisplayAvailable, false);
61 
62         assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
63     }
64 }
65