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:
@@ -16,18 +16,26 @@
|
||||
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.hardware.AmbientDisplayConfiguration;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
|
||||
import com.android.settings.search.InlinePayload;
|
||||
import com.android.settings.search.InlineSwitchPayload;
|
||||
import com.android.settings.search.ResultPayload;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -37,12 +45,10 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@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 DoubleTapScreenPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@@ -60,6 +66,11 @@ public class DoubleTapScreenPreferenceControllerTest {
|
||||
mContext, null, mAmbientDisplayConfiguration, 0, KEY_DOUBLE_TAP_SCREEN);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
when(mAmbientDisplayConfiguration.pulseOnDoubleTapAvailable()).thenReturn(true);
|
||||
@@ -125,4 +136,36 @@ public class DoubleTapScreenPreferenceControllerTest {
|
||||
|
||||
assertThat(newValue).isEqualTo(currentValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionCompleted_ambientDisplay_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
|
||||
// No stored value in shared preferences if not visited yet.
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
||||
.getSharedPrefs(context);
|
||||
|
||||
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionCompleted_ambientDisplay_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeComponent, "foo");
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.string.config_dozeDoubleTapSensorType, "bar");
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
final SharedPreferences prefs = new SuggestionFeatureProviderImpl(context)
|
||||
.getSharedPrefs(context);
|
||||
|
||||
prefs.edit().putBoolean(
|
||||
DoubleTapScreenSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
|
||||
|
||||
assertThat(DoubleTapScreenPreferenceController.isSuggestionComplete(context, prefs))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user