Merge "Update Wi-Fi Wakeup setting to check whether the feature is available." into oc-dev

This commit is contained in:
TreeHugger Robot
2017-05-11 00:05:48 +00:00
committed by Android (Google) Code Review
4 changed files with 48 additions and 10 deletions

View File

@@ -127,6 +127,16 @@ public class SettingsShadowResources extends ShadowResources {
realResources, Resources.class, "getString", ClassParameter.from(int.class, id));
}
@Implementation
public int getInteger(int id) {
final Object override = sResourceOverrides.get(id);
if (override instanceof Integer) {
return (Integer) override;
}
return Shadow.directlyOn(
realResources, Resources.class, "getInteger", ClassParameter.from(int.class, id));
}
@Implements(Theme.class)
public static class SettingsShadowTheme extends ShadowTheme {

View File

@@ -18,10 +18,9 @@ package com.android.settings.wifi;
import static android.provider.Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED;
import static android.provider.Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_AVAILABLE;
import static android.provider.Settings.Global.WIFI_WAKEUP_ENABLED;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -34,7 +33,9 @@ import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.core.lifecycle.Lifecycle;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -43,7 +44,10 @@ 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 WifiWakeupPreferenceControllerTest {
private Context mContext;
@@ -55,10 +59,24 @@ public class WifiWakeupPreferenceControllerTest {
mContext = RuntimeEnvironment.application;
mController = new WifiWakeupPreferenceController(mContext, mock(Lifecycle.class));
Settings.System.putInt(mContext.getContentResolver(), WIFI_SCAN_ALWAYS_AVAILABLE, 1);
SettingsShadowResources.overrideResource(
com.android.internal.R.integer.config_wifi_wakeup_available, 0);
}
@After
public void tearDown() {
SettingsShadowResources.reset();
}
@Test
public void testIsAvailable_shouldAlwaysReturnTrue() {
public void testIsAvailable_returnsFalseWhenSettingIsNotAvailable() {
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_AVAILABLE, 0);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void testIsAvailable_returnsTrueWhenSettingIsAvailable() {
Settings.System.putInt(mContext.getContentResolver(), WIFI_WAKEUP_AVAILABLE, 1);
assertThat(mController.isAvailable()).isTrue();
}