Change def value for LOW_POWER_MODE_TRIGGER_LEVEL

Fixes: 73668682
Test: RunSettingsRoboTests
Change-Id: I2122523c958f12bbdd658ae53d63b00769db3520
This commit is contained in:
jackqdyulei
2018-02-20 18:15:24 -08:00
parent 49c8080a50
commit da7ac699fb
4 changed files with 35 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ import android.support.v14.preference.SwitchPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.Before;
import org.junit.Test;
@@ -34,7 +35,8 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@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 AutoBatterySaverPreferenceControllerTest {
private AutoBatterySaverPreferenceController mController;
@@ -45,6 +47,8 @@ public class AutoBatterySaverPreferenceControllerTest {
public void setUp() {
MockitoAnnotations.initMocks(this);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_lowBatteryWarningLevel, 15);
mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext);
mController = new AutoBatterySaverPreferenceController(mContext);
@@ -84,4 +88,9 @@ public class AutoBatterySaverPreferenceControllerTest {
Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0)).isEqualTo(0);
}
@Test
public void testIsChecked_useDefaultValue_returnTrue() {
assertThat(mController.isChecked()).isTrue();
}
}

View File

@@ -24,6 +24,7 @@ import android.support.v14.preference.SwitchPreference;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.SeekBarPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -35,9 +36,11 @@ import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@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 AutoBatterySeekBarPreferenceControllerTest {
private static final int TRIGGER_LEVEL = 15;
private static final int TRIGGER_LEVEL = 20;
private static final int DEFAULT_LEVEL = 15;
private AutoBatterySeekBarPreferenceController mController;
private Context mContext;
@@ -51,6 +54,8 @@ public class AutoBatterySeekBarPreferenceControllerTest {
mLifecycleOwner = () -> mLifecycle;
mLifecycle = new Lifecycle(mLifecycleOwner);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_lowBatteryWarningLevel, DEFAULT_LEVEL);
mContext = RuntimeEnvironment.application;
mPreference = new SeekBarPreference(mContext);
mPreference.setMax(100);
@@ -67,6 +72,14 @@ public class AutoBatterySeekBarPreferenceControllerTest {
assertThat(mPreference.isVisible()).isFalse();
}
@Test
public void testPreference_defaultValue_preferenceVisible() {
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getProgress()).isEqualTo(DEFAULT_LEVEL);
}
@Test
public void testPreference_lowPowerLevelNotZero_updatePreference() {
Settings.Global.putInt(mContext.getContentResolver(),
@@ -74,7 +87,7 @@ public class AutoBatterySeekBarPreferenceControllerTest {
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
assertThat(mPreference.getTitle()).isEqualTo("Turn on automatically at 15%");
assertThat(mPreference.getTitle()).isEqualTo("Turn on automatically at 20%");
assertThat(mPreference.getProgress()).isEqualTo(TRIGGER_LEVEL);
}