Use external/robolectric-shadows/run_robotests.mk
This allows Settings to test against the latest framework changes. Also replaced TestConfig with traditional robolectric.properties. Bug: 73173204 Bug: 73892008 Test: make -j56 RunSettingsRoboTests Change-Id: I3135b4fa5f095ba79b282a76f45dd9baa2584bc7
This commit is contained in:
@@ -17,32 +17,24 @@
|
||||
package com.android.settings.development;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.support.v14.preference.SwitchPreference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH,
|
||||
sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {SettingsShadowSystemProperties.class})
|
||||
public class ShowLayoutBoundsPreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
@@ -50,30 +42,23 @@ public class ShowLayoutBoundsPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mPreferenceScreen;
|
||||
|
||||
private Context mContext;
|
||||
private ShowLayoutBoundsPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new ShowLayoutBoundsPreferenceController(mContext);
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
|
||||
mPreference);
|
||||
mController = new ShowLayoutBoundsPreferenceController(RuntimeEnvironment.application);
|
||||
when(mPreferenceScreen.findPreference(mController.getPreferenceKey()))
|
||||
.thenReturn(mPreference);
|
||||
mController.displayPreference(mPreferenceScreen);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowSystemProperties.clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChanged_settingEnabled_turnOnShowLayoutBounds() {
|
||||
mController.onPreferenceChange(mPreference, true /* new value */);
|
||||
|
||||
final boolean mode = SettingsShadowSystemProperties.getBoolean(
|
||||
View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
final boolean mode =
|
||||
SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
|
||||
assertThat(mode).isTrue();
|
||||
}
|
||||
@@ -82,16 +67,15 @@ public class ShowLayoutBoundsPreferenceControllerTest {
|
||||
public void onPreferenceChanged_settingDisabled_turnOffShowLayoutBounds() {
|
||||
mController.onPreferenceChange(mPreference, false /* new value */);
|
||||
|
||||
final boolean mode = SettingsShadowSystemProperties.getBoolean(
|
||||
View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
final boolean mode =
|
||||
SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
|
||||
assertThat(mode).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_settingEnabled_preferenceShouldBeChecked() {
|
||||
SettingsShadowSystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
|
||||
Boolean.toString(true));
|
||||
SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, Boolean.toString(true));
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(true);
|
||||
@@ -99,8 +83,7 @@ public class ShowLayoutBoundsPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
|
||||
SettingsShadowSystemProperties.set(View.DEBUG_LAYOUT_PROPERTY,
|
||||
Boolean.toString(false));
|
||||
SystemProperties.set(View.DEBUG_LAYOUT_PROPERTY, Boolean.toString(false));
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setChecked(false);
|
||||
@@ -110,8 +93,8 @@ public class ShowLayoutBoundsPreferenceControllerTest {
|
||||
public void onDeveloperOptionsDisabled_shouldDisablePreference() {
|
||||
mController.onDeveloperOptionsDisabled();
|
||||
|
||||
final boolean mode = SettingsShadowSystemProperties.getBoolean(
|
||||
View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
final boolean mode =
|
||||
SystemProperties.getBoolean(View.DEBUG_LAYOUT_PROPERTY, false /* default */);
|
||||
|
||||
assertThat(mode).isFalse();
|
||||
verify(mPreference).setEnabled(false);
|
||||
|
Reference in New Issue
Block a user