• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 import static org.mockito.ArgumentMatchers.anyInt;
21 import static org.mockito.Mockito.verify;
22 import static org.mockito.Mockito.when;
23 
24 import android.content.Context;
25 import android.support.v7.preference.Preference;
26 
27 import com.android.internal.hardware.AmbientDisplayConfiguration;
28 import com.android.settings.R;
29 import com.android.settings.testutils.SettingsRobolectricTestRunner;
30 import com.android.settings.testutils.shadow.ShadowSecureSettings;
31 
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.mockito.Mock;
36 import org.mockito.MockitoAnnotations;
37 import org.robolectric.annotation.Config;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 @Config(shadows = ShadowSecureSettings.class)
41 public class AmbientDisplayPreferenceControllerTest {
42 
43     @Mock
44     private Context mContext;
45     @Mock
46     private AmbientDisplayConfiguration mConfig;
47     @Mock
48     private Preference mPreference;
49 
50     private AmbientDisplayPreferenceController mController;
51 
52     @Before
setUp()53     public void setUp() {
54         MockitoAnnotations.initMocks(this);
55         mController = new AmbientDisplayPreferenceController(mContext, mConfig, "key");
56     }
57 
58     @Test
isAvailable_available()59     public void isAvailable_available() {
60         when(mConfig.available()).thenReturn(true);
61         assertThat(mController.isAvailable()).isTrue();
62     }
63 
64     @Test
isAvailable_unavailable()65     public void isAvailable_unavailable() {
66         when(mConfig.available()).thenReturn(false);
67         assertThat(mController.isAvailable()).isFalse();
68     }
69 
70     @Test
updateState_alwaysOn()71     public void updateState_alwaysOn() {
72         when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(true);
73 
74         mController.updateState(mPreference);
75 
76         verify(mPreference).setSummary(R.string.ambient_display_screen_summary_always_on);
77     }
78 
79     @Test
updateState_notifications()80     public void updateState_notifications() {
81         when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(false);
82         when(mConfig.pulseOnNotificationEnabled(anyInt())).thenReturn(true);
83 
84         mController.updateState(mPreference);
85 
86         verify(mPreference).setSummary(R.string.ambient_display_screen_summary_notifications);
87     }
88 
89     @Test
updateState_gestures()90     public void updateState_gestures() {
91         when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(false);
92         when(mConfig.pulseOnNotificationEnabled(anyInt())).thenReturn(false);
93         when(mConfig.enabled(anyInt())).thenReturn(true);
94 
95         mController.updateState(mPreference);
96 
97         verify(mPreference).setSummary(R.string.switch_on_text);
98     }
99 
100     @Test
updateState_off()101     public void updateState_off() {
102         when(mConfig.alwaysOnEnabled(anyInt())).thenReturn(false);
103         when(mConfig.pulseOnNotificationEnabled(anyInt())).thenReturn(false);
104         when(mConfig.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
105         when(mConfig.pulseOnPickupEnabled(anyInt())).thenReturn(false);
106 
107         mController.updateState(mPreference);
108 
109         verify(mPreference).setSummary(R.string.switch_off_text);
110     }
111 
112     @Test
getPreferenceKey()113     public void getPreferenceKey() {
114         assertThat(mController.getPreferenceKey()).isEqualTo("key");
115     }
116 }