Move code from SuggestionChecks to FeatureProvider

This is step one to deprecate SuggestionChecks. Moving logic into
SuggestionFeatureProvider allows potential logic override and improves
testability.

Also moved isSuggestionComplete tests to corresponding activity/pref
controller test.

Bug: 65065268
Test: robotests
Change-Id: I2071d30fc58bb84acad2083ca03cfcf7d41f10cb
This commit is contained in:
Fan Zhang
2017-09-28 17:17:44 -07:00
parent b963125159
commit 31f699c281
23 changed files with 497 additions and 411 deletions

View File

@@ -16,38 +16,44 @@
package com.android.settings.gestures;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.UserManager;
import android.provider.Settings;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.UserManager;
import android.provider.Settings;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
import com.android.settings.testutils.shadow.ShadowDoubleTwistPreferenceController;
import com.android.settings.testutils.shadow.ShadowSecureSettings;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowApplication;
import java.util.ArrayList;
import java.util.List;
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
SettingsShadowResources.class
})
public class DoubleTwistPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
@@ -64,6 +70,11 @@ public class DoubleTwistPreferenceControllerTest {
mController = new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST);
}
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Test
public void isAvailable_hasSensor_shouldReturnTrue() {
// Mock sensors
@@ -96,6 +107,18 @@ public class DoubleTwistPreferenceControllerTest {
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isSuggestionCompleted_doubleTwist_trueWhenNotAvailable() {
SettingsShadowResources.overrideResource(
R.string.gesture_double_twist_sensor_name, "nonexistant name");
SettingsShadowResources.overrideResource(
R.string.gesture_double_twist_sensor_vendor, "nonexistant vendor");
assertThat(DoubleTwistPreferenceController.isSuggestionComplete(
RuntimeEnvironment.application, null /* prefs */))
.isTrue();
}
@Test
@Config(shadows = {
ShadowDoubleTwistPreferenceController.class,
@@ -103,9 +126,9 @@ public class DoubleTwistPreferenceControllerTest {
public void onPreferenceChange_hasWorkProfile_shouldUpdateSettingForWorkProfileUser() {
final int managedId = 2;
ShadowSecureSettings.putIntForUser(
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
null, Settings.Secure.CAMERA_DOUBLE_TWIST_TO_FLIP_ENABLED, 0, managedId);
DoubleTwistPreferenceController controller =
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
spy(new DoubleTwistPreferenceController(mContext, null, KEY_DOUBLE_TWIST));
ShadowDoubleTwistPreferenceController.setManagedProfileId(managedId);
// enable the gesture