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.gestures; 18 19 import static com.android.settings.core.BasePreferenceController.AVAILABLE; 20 21 import static com.google.common.truth.Truth.assertThat; 22 23 import android.app.Activity; 24 25 import com.android.settings.testutils.FakeFeatureFactory; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 import org.mockito.Answers; 32 import org.mockito.Mock; 33 import org.mockito.MockitoAnnotations; 34 import org.robolectric.RobolectricTestRunner; 35 import org.robolectric.RuntimeEnvironment; 36 import org.robolectric.util.ReflectionHelpers; 37 38 import java.util.ArrayList; 39 import java.util.List; 40 41 @RunWith(RobolectricTestRunner.class) 42 public class GesturesSettingsPreferenceControllerTest { 43 44 @Mock(answer = Answers.RETURNS_DEEP_STUBS) 45 private Activity mActivity; 46 47 private GesturesSettingPreferenceController mController; 48 49 @Before setUp()50 public void setUp() { 51 MockitoAnnotations.initMocks(this); 52 FakeFeatureFactory.setupForTest(); 53 mController = new GesturesSettingPreferenceController(mActivity); 54 } 55 56 @Test isAvailable_hasGesture_shouldReturnTrue()57 public void isAvailable_hasGesture_shouldReturnTrue() { 58 final List<AbstractPreferenceController> mControllers = new ArrayList<>(); 59 mControllers.add(new AbstractPreferenceController(RuntimeEnvironment.application) { 60 @Override 61 public boolean isAvailable() { 62 return true; 63 } 64 65 @Override 66 public String getPreferenceKey() { 67 return "test_key"; 68 } 69 }); 70 ReflectionHelpers.setField(mController, "mGestureControllers", mControllers); 71 72 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); 73 } 74 75 @Test isAvailable_noGesture_shouldReturnFalse()76 public void isAvailable_noGesture_shouldReturnFalse() { 77 ReflectionHelpers.setField(mController, "mGestureControllers", 78 new ArrayList<AbstractPreferenceController>()); 79 80 assertThat(mController.isAvailable()).isFalse(); 81 } 82 } 83