1 /*
2  * Copyright (C) 2023 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.accessibility;
18 
19 import static com.android.settings.accessibility.ShadowFlashNotificationsUtils.setFlashNotificationsState;
20 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
21 
22 import static com.google.common.truth.Truth.assertThat;
23 
24 import android.content.Context;
25 
26 import androidx.test.core.app.ApplicationProvider;
27 
28 import com.android.settings.R;
29 
30 import org.junit.After;
31 import org.junit.Before;
32 import org.junit.Rule;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.MockitoAnnotations;
36 import org.mockito.Spy;
37 import org.mockito.junit.MockitoJUnit;
38 import org.mockito.junit.MockitoRule;
39 import org.robolectric.RobolectricTestRunner;
40 import org.robolectric.annotation.Config;
41 
42 @RunWith(RobolectricTestRunner.class)
43 @Config(shadows = ShadowFlashNotificationsUtils.class)
44 public class FlashNotificationsPreferenceControllerTest {
45     private static final String PREFERENCE_KEY = "preference_key";
46 
47     @Rule
48     public MockitoRule mMockitoRule = MockitoJUnit.rule();
49     @Spy
50     private final Context mContext = ApplicationProvider.getApplicationContext();
51 
52     private FlashNotificationsPreferenceController mController;
53 
54     @Before
setUp()55     public void setUp() {
56         MockitoAnnotations.initMocks(this);
57         mController = new FlashNotificationsPreferenceController(mContext, PREFERENCE_KEY);
58     }
59 
60     @After
tearDown()61     public void tearDown() {
62         ShadowFlashNotificationsUtils.reset();
63     }
64 
65     @Test
getAvailabilityStatus()66     public void getAvailabilityStatus() {
67         assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
68     }
69 
70     @Test
getSummary_stateOff_assertOff()71     public void getSummary_stateOff_assertOff() {
72         setFlashNotificationsState(FlashNotificationsUtil.State.OFF);
73 
74         assertThat(mController.getSummary().toString()).isEqualTo(mContext.getString(
75                 R.string.flash_notifications_summary_off));
76     }
77 
78     @Test
getSummary_stateCamera_assertCamera()79     public void getSummary_stateCamera_assertCamera() {
80         setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA);
81 
82         assertThat(mController.getSummary().toString()).isEqualTo(mContext.getString(
83                 R.string.flash_notifications_summary_on_camera));
84     }
85 
86     @Test
getSummary_stateScreen_assertScreen()87     public void getSummary_stateScreen_assertScreen() {
88         setFlashNotificationsState(FlashNotificationsUtil.State.SCREEN);
89 
90         assertThat(mController.getSummary().toString()).isEqualTo(mContext.getString(
91                 R.string.flash_notifications_summary_on_screen));
92     }
93 
94     @Test
getSummary_stateCameraScreen_assertCameraScreen()95     public void getSummary_stateCameraScreen_assertCameraScreen() {
96         setFlashNotificationsState(FlashNotificationsUtil.State.CAMERA_SCREEN);
97 
98         assertThat(mController.getSummary().toString()).isEqualTo(mContext.getString(
99                 R.string.flash_notifications_summary_on_camera_and_screen));
100     }
101 }
102