Use binary resource support in robolectric

The resources available to tests are now exactly the merged resources
located in the APK under test.

Bug: 74359828
Test: make -j56 RunSettingsRoboTests
Change-Id: I050db81a92decefea23314b5ec7a62f77ff4bb2b
This commit is contained in:
James Lemieux
2018-12-07 12:56:49 -08:00
committed by Fan Zhang
parent 1f5fab1480
commit f1dade40d2
1005 changed files with 3187 additions and 5478 deletions

View File

@@ -21,10 +21,9 @@ import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_UNSPECIFIED;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
@@ -41,7 +40,6 @@ import android.os.UserManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedSwitchPreference;
@@ -51,10 +49,11 @@ import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
@RunWith(SettingsRobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class AllowSoundPreferenceControllerTest {
private Context mContext;
@@ -84,14 +83,14 @@ public class AllowSoundPreferenceControllerTest {
}
@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_notIfNull() throws Exception {
public void testIsAvailable_notIfNull() {
mController.onResume(null, mock(NotificationChannel.class), null, null);
assertFalse(mController.isAvailable());
@@ -100,7 +99,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testIsAvailable_notIfAppBlocked() throws Exception {
public void testIsAvailable_notIfAppBlocked() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
@@ -108,7 +107,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testIsAvailable_notIfAppCreatedChannel() throws Exception {
public void testIsAvailable_notIfAppCreatedChannel() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getId()).thenReturn("something new");
@@ -117,7 +116,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testIsAvailable() throws Exception {
public void testIsAvailable() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
@@ -127,7 +126,7 @@ public class AllowSoundPreferenceControllerTest {
}
@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(
@@ -140,7 +139,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testUpdateState_notConfigurable() throws Exception {
public void testUpdateState_notConfigurable() {
String lockedId = "locked";
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.lockedChannelId = lockedId;
@@ -155,7 +154,7 @@ public class AllowSoundPreferenceControllerTest {
}
@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");
@@ -168,7 +167,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testUpdateState_checkedForHighImportanceChannel() throws Exception {
public void testUpdateState_checkedForHighImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
@@ -179,7 +178,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testUpdateState_checkedForUnspecifiedImportanceChannel() throws Exception {
public void testUpdateState_checkedForUnspecifiedImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_UNSPECIFIED);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);
@@ -190,7 +189,7 @@ public class AllowSoundPreferenceControllerTest {
}
@Test
public void testUpdateState_notCheckedForLowImportanceChannel() throws Exception {
public void testUpdateState_notCheckedForLowImportanceChannel() {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_LOW);
mController.onResume(new NotificationBackend.AppRow(), channel, null, null);