1 /*
2  * Copyright (C) 2020 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 static com.google.common.truth.Truth.assertThat;
20 
21 import static org.mockito.Mockito.mock;
22 import static org.mockito.Mockito.spy;
23 import static org.mockito.Mockito.when;
24 
25 import android.content.Context;
26 import android.content.res.Resources;
27 
28 import com.android.settings.core.BasePreferenceController;
29 
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.robolectric.RobolectricTestRunner;
34 import org.robolectric.RuntimeEnvironment;
35 
36 @RunWith(RobolectricTestRunner.class)
37 public class PowerMenuPreferenceControllerTest {
38     private Context mContext;
39     private Resources mResources;
40     private PowerMenuPreferenceController mController;
41 
42     private static final String KEY_GESTURE_POWER_MENU = "gesture_power_menu";
43 
44 
45     @Before
setUp()46     public void setUp() {
47         mContext = spy(RuntimeEnvironment.application);
48         mResources = mock(Resources.class);
49         when(mResources.getBoolean(
50             com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
51                 .thenReturn(true);
52         when(mContext.getResources()).thenReturn(mResources);
53         mController = new PowerMenuPreferenceController(mContext, KEY_GESTURE_POWER_MENU);
54     }
55 
56     @Test
getAvailabilityStatus_assistAvailable_available()57     public void getAvailabilityStatus_assistAvailable_available() {
58         when(mResources.getBoolean(
59                 com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
60                     .thenReturn(true);
61 
62         assertThat(mController.getAvailabilityStatus()).isEqualTo(
63                 BasePreferenceController.AVAILABLE);
64     }
65 
66     @Test
getAvailabilityStatus_assistUnavailable_unavailable()67     public void getAvailabilityStatus_assistUnavailable_unavailable() {
68         when(mResources.getBoolean(
69                 com.android.internal.R.bool.config_longPressOnPowerForAssistantSettingAvailable))
70                     .thenReturn(false);
71 
72         assertThat(mController.getAvailabilityStatus()).isEqualTo(
73                 BasePreferenceController.UNSUPPORTED_ON_DEVICE);
74     }
75 }
76