DoubleTapPowerPreferenceControllerTest.java revision 33b0d91d74bb29cbfd49e3f4c3ebd9d99001bfa9
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 17package com.android.settings.gestures; 18 19import android.content.Context; 20import android.provider.Settings; 21import android.support.v7.preference.PreferenceScreen; 22 23import com.android.settings.SettingsRobolectricTestRunner; 24import com.android.settings.TestConfig; 25 26import org.junit.Before; 27import org.junit.Test; 28import org.junit.runner.RunWith; 29import org.mockito.Answers; 30import org.mockito.Mock; 31import org.mockito.MockitoAnnotations; 32import org.robolectric.annotation.Config; 33import org.robolectric.shadows.ShadowApplication; 34 35import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED; 36import static com.google.common.truth.Truth.assertThat; 37import static org.mockito.Mockito.when; 38 39@RunWith(SettingsRobolectricTestRunner.class) 40@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) 41public class DoubleTapPowerPreferenceControllerTest { 42 43 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 44 private Context mContext; 45 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 46 private PreferenceScreen mScreen; 47 private DoubleTapPowerPreferenceController mController; 48 49 @Before 50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 mController = new DoubleTapPowerPreferenceController(mContext, null); 53 } 54 55 @Test 56 public void isAvailable_configIsTrue_shouldReturnTrue() { 57 when(mContext.getResources(). 58 getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled)) 59 .thenReturn(true); 60 61 assertThat(mController.isAvailable()).isTrue(); 62 } 63 64 @Test 65 public void isAvailable_configIsTrue_shouldReturnFalse() { 66 when(mContext.getResources(). 67 getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled)) 68 .thenReturn(false); 69 70 assertThat(mController.isAvailable()).isFalse(); 71 } 72 73 @Test 74 public void testSwitchEnabled_configIsNotSet_shouldReturnTrue() { 75 // Set the setting to be enabled. 76 final Context context = ShadowApplication.getInstance().getApplicationContext(); 77 Settings.System.putInt(context.getContentResolver(), 78 CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0); 79 mController = new DoubleTapPowerPreferenceController(context, null); 80 81 assertThat(mController.isSwitchPrefEnabled()).isTrue(); 82 } 83 84 @Test 85 public void testSwitchEnabled_configIsSet_shouldReturnFalse() { 86 // Set the setting to be disabled. 87 final Context context = ShadowApplication.getInstance().getApplicationContext(); 88 Settings.System.putInt(context.getContentResolver(), 89 CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 1); 90 mController = new DoubleTapPowerPreferenceController(context, null); 91 92 assertThat(mController.isSwitchPrefEnabled()).isFalse(); 93 } 94} 95