1 /*
2  * Copyright (C) 2016 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.gestures;
18 
19 import android.content.Context;
20 
21 import com.android.internal.hardware.AmbientDisplayConfiguration;
22 import com.android.settings.SettingsRobolectricTestRunner;
23 import com.android.settings.TestConfig;
24 
25 import com.android.settings.search2.InlineSwitchPayload;
26 import com.android.settings.search2.ResultPayload;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.Answers;
31 import org.mockito.Mock;
32 import org.mockito.MockitoAnnotations;
33 import org.robolectric.annotation.Config;
34 
35 import static com.google.common.truth.Truth.assertThat;
36 import static org.mockito.Matchers.anyInt;
37 import static org.mockito.Mockito.when;
38 
39 @RunWith(SettingsRobolectricTestRunner.class)
40 @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
41 public class DoubleTapScreenPreferenceControllerTest {
42 
43     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
44     private Context mContext;
45     @Mock
46     private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
47     private DoubleTapScreenPreferenceController mController;
48 
49     private static final String KEY_DOUBLE_TAP_SCREEN = "gesture_double_tap_screen";
50 
51     @Before
setUp()52     public void setUp() {
53         MockitoAnnotations.initMocks(this);
54         mController = new DoubleTapScreenPreferenceController(
55                 mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
56     }
57 
58     @Test
isAvailable_configIsTrue_shouldReturnTrue()59     public void isAvailable_configIsTrue_shouldReturnTrue() {
60         when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
61 
62         assertThat(mController.isAvailable()).isTrue();
63     }
64 
65     @Test
isAvailable_configIsFalse_shouldReturnFalse()66     public void isAvailable_configIsFalse_shouldReturnFalse() {
67         when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(false);
68 
69         assertThat(mController.isAvailable()).isFalse();
70     }
71 
72     @Test
testSwitchEnabled_configIsSet_shouldReturnTrue()73     public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
74         // Set the setting to be enabled.
75         when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(true);
76 
77         assertThat(mController.isSwitchPrefEnabled()).isTrue();
78     }
79 
80     @Test
testSwitchEnabled_configIsNotSet_shouldReturnFalse()81     public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
82         when(mAmbientDisplayConfiguration.pulseOnDoubleTapEnabled(anyInt())).thenReturn(false);
83 
84         assertThat(mController.isSwitchPrefEnabled()).isFalse();
85     }
86 }
87