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:
@@ -21,10 +21,8 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
|
||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.provider.Settings.System.NOTIFICATION_LIGHT_PULSE;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -41,7 +39,6 @@ import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -58,9 +55,7 @@ import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||
SettingsShadowResources.class,
|
||||
})
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class LightsPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@@ -81,7 +76,7 @@ public class LightsPreferenceControllerTest {
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNm);
|
||||
shadowApplication.setSystemService(Context.USER_SERVICE, mUm);
|
||||
mContext = shadowApplication.getApplicationContext();
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = spy(new LightsPreferenceController(mContext, mBackend));
|
||||
|
||||
// By default allow lights
|
||||
@@ -91,14 +86,14 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoCrashIfNoOnResume() throws Exception {
|
||||
public void testNoCrashIfNoOnResume() {
|
||||
mController.isAvailable();
|
||||
mController.updateState(mock(RestrictedSwitchPreference.class));
|
||||
mController.onPreferenceChange(mock(RestrictedSwitchPreference.class), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfConfigNotAllowed() throws Exception {
|
||||
public void testIsAvailable_notIfConfigNotAllowed() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_intrusiveNotificationLed, false);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
@@ -108,7 +103,7 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfSettingNotAllowed() throws Exception {
|
||||
public void testIsAvailable_notIfSettingNotAllowed() {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, 0);
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||
@@ -117,7 +112,7 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfNotImportant() throws Exception {
|
||||
public void testIsAvailable_notIfNotImportant() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_LOW);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
@@ -125,7 +120,7 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable_notIfDefaultChannel() throws Exception {
|
||||
public void testIsAvailable_notIfDefaultChannel() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel =
|
||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "", IMPORTANCE_DEFAULT);
|
||||
@@ -134,7 +129,7 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() throws Exception {
|
||||
public void testIsAvailable() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_DEFAULT);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
@@ -142,20 +137,20 @@ public class LightsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_disabledByAdmin() throws Exception {
|
||||
public void testUpdateState_disabledByAdmin() {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getId()).thenReturn("something");
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, mock(
|
||||
RestrictedLockUtils.EnforcedAdmin.class));
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
||||
mock(RestrictedLockUtils.EnforcedAdmin.class));
|
||||
|
||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
|
||||
assertFalse(pref.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_notConfigurable() throws Exception {
|
||||
public void testUpdateState_notConfigurable() {
|
||||
String lockedId = "locked";
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
appRow.lockedChannelId = lockedId;
|
||||
@@ -163,45 +158,43 @@ public class LightsPreferenceControllerTest {
|
||||
when(channel.getId()).thenReturn(lockedId);
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
|
||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
|
||||
assertFalse(pref.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_configurable() throws Exception {
|
||||
public void testUpdateState_configurable() {
|
||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.getId()).thenReturn("something");
|
||||
mController.onResume(appRow, channel, null, null);
|
||||
|
||||
Preference pref = new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
|
||||
assertTrue(pref.isEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_lightsOn() throws Exception {
|
||||
public void testUpdateState_lightsOn() {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.shouldShowLights()).thenReturn(true);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
assertTrue(pref.isChecked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState_lightsOff() throws Exception {
|
||||
public void testUpdateState_lightsOff() {
|
||||
NotificationChannel channel = mock(NotificationChannel.class);
|
||||
when(channel.shouldShowLights()).thenReturn(false);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||
mController.updateState(pref);
|
||||
assertFalse(pref.isChecked());
|
||||
}
|
||||
@@ -212,8 +205,7 @@ public class LightsPreferenceControllerTest {
|
||||
new NotificationChannel(DEFAULT_CHANNEL_ID, "a", IMPORTANCE_DEFAULT);
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
RestrictedSwitchPreference pref = new RestrictedSwitchPreference(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(pref);
|
||||
@@ -231,7 +223,7 @@ public class LightsPreferenceControllerTest {
|
||||
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
|
||||
|
||||
RestrictedSwitchPreference pref =
|
||||
new RestrictedSwitchPreference(RuntimeEnvironment.application);
|
||||
new RestrictedSwitchPreference(mContext);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(pref);
|
||||
mController.displayPreference(mScreen);
|
||||
mController.updateState(pref);
|
||||
|
Reference in New Issue
Block a user