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 PIckupGesturePreferenceControllerTest {
42 
43     @Mock(answer = Answers.RETURNS_DEEP_STUBS)
44     private Context mContext;
45     @Mock
46     private AmbientDisplayConfiguration mAmbientDisplayConfiguration;
47 
48     private PickupGesturePreferenceController mController;
49 
50     private static final String KEY_PICK_UP = "gesture_pick_up";
51 
52     @Before
setUp()53     public void setUp() {
54         MockitoAnnotations.initMocks(this);
55         mController = new PickupGesturePreferenceController(
56                 mContext, null, mAmbientDisplayConfiguration, 0, KEY_PICK_UP);
57     }
58 
59     @Test
isAvailable_configIsTrue_shouldReturnTrue()60     public void isAvailable_configIsTrue_shouldReturnTrue() {
61         when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(true);
62 
63         assertThat(mController.isAvailable()).isTrue();
64     }
65 
66     @Test
isAvailable_configIsFalse_shouldReturnFalse()67     public void isAvailable_configIsFalse_shouldReturnFalse() {
68         when(mAmbientDisplayConfiguration.pulseOnPickupAvailable()).thenReturn(false);
69 
70         assertThat(mController.isAvailable()).isFalse();
71     }
72 
73     @Test
testSwitchEnabled_configIsSet_shouldReturnTrue()74     public void testSwitchEnabled_configIsSet_shouldReturnTrue() {
75         // Set the setting to be enabled.
76         when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(true);
77 
78         assertThat(mController.isSwitchPrefEnabled()).isTrue();
79     }
80 
81     @Test
testSwitchEnabled_configIsNotSet_shouldReturnFalse()82     public void testSwitchEnabled_configIsNotSet_shouldReturnFalse() {
83         // Set the setting to be disabled.
84         when(mAmbientDisplayConfiguration.pulseOnPickupEnabled(anyInt())).thenReturn(false);
85 
86         assertThat(mController.isSwitchPrefEnabled()).isFalse();
87     }
88 }
89