Migrate from strongly discouraged `@Test(expected = ...)` to `assertThrows(...)`.

PiperOrigin-RevId: 434925970
diff --git a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java
index eb0b2e8..6a06d5e 100644
--- a/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java
+++ b/integration_tests/ctesque/src/sharedTest/java/android/content/res/ResourcesTest.java
@@ -21,6 +21,7 @@
 import static android.util.TypedValue.TYPE_STRING;
 import static android.util.TypedValue.applyDimension;
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 import static org.junit.Assume.assumeFalse;
 import static org.robolectric.testapp.R.color.test_ARGB8;
@@ -337,14 +338,14 @@
     assertThat(resources.getBoolean(R.bool.reference_to_true)).isEqualTo(true);
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void getStringArray_shouldThrowExceptionIfNotFound() {
-    resources.getStringArray(-1);
+    assertThrows(Resources.NotFoundException.class, () -> resources.getStringArray(-1));
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void getIntegerArray_shouldThrowExceptionIfNotFound() {
-    resources.getIntArray(-1);
+    assertThrows(Resources.NotFoundException.class, () -> resources.getIntArray(-1));
   }
 
   @Test
@@ -395,9 +396,11 @@
     assertThat(resources.newTheme()).isNotNull();
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void testGetDrawableNullRClass() {
-    assertThat(resources.getDrawable(-12345)).isInstanceOf(BitmapDrawable.class);
+    assertThrows(
+        Resources.NotFoundException.class,
+        () -> assertThat(resources.getDrawable(-12345)).isInstanceOf(BitmapDrawable.class));
   }
 
   @Test
@@ -422,9 +425,9 @@
     assertThat(resources.getColor(R.color.background)).isEqualTo(0xfff5f5f5);
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void testGetColor_Missing() {
-    resources.getColor(11234);
+    assertThrows(Resources.NotFoundException.class, () -> resources.getColor(11234));
   }
 
   @Test
@@ -442,9 +445,13 @@
     assertThat(resources.getDrawable(R.drawable.nine_patch_drawable)).isInstanceOf(NinePatchDrawable.class);
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void testGetBitmapDrawableForUnknownId() {
-    assertThat(resources.getDrawable(Integer.MAX_VALUE)).isInstanceOf(BitmapDrawable.class);
+    assertThrows(
+        Resources.NotFoundException.class,
+        () ->
+            assertThat(resources.getDrawable(Integer.MAX_VALUE))
+                .isInstanceOf(BitmapDrawable.class));
   }
 
   @Test
@@ -579,14 +586,14 @@
     assertThat(findRootTag(parser)).isEqualTo("selector");
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void testGetXml_nonexistentResource() {
-    resources.getXml(0);
+    assertThrows(Resources.NotFoundException.class, () -> resources.getXml(0));
   }
 
-  @Test(expected = Resources.NotFoundException.class)
+  @Test
   public void testGetXml_nonxmlfile() {
-    resources.getXml(R.drawable.an_image);
+    assertThrows(Resources.NotFoundException.class, () -> resources.getXml(R.drawable.an_image));
   }
 
   @Test
diff --git a/integration_tests/ctesque/src/sharedTest/java/android/graphics/MatrixTest.java b/integration_tests/ctesque/src/sharedTest/java/android/graphics/MatrixTest.java
index 5de6147..14ecd5b 100644
--- a/integration_tests/ctesque/src/sharedTest/java/android/graphics/MatrixTest.java
+++ b/integration_tests/ctesque/src/sharedTest/java/android/graphics/MatrixTest.java
@@ -1,6 +1,7 @@
 package android.graphics;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
 
 import android.graphics.Matrix.ScaleToFit;
 import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -33,9 +34,9 @@
     assertThat(value[0]).isEqualTo(100f);
   }
 
-  @Test(expected = Exception.class)
+  @Test
   public void mapPointsNull() {
-    new Matrix().mapPoints(null);
+    assertThrows(Exception.class, () -> new Matrix().mapPoints(null));
   }
 
   @Test
@@ -48,9 +49,9 @@
     assertThat(dst[0]).isEqualTo(200f);
   }
 
-  @Test(expected = Exception.class)
+  @Test
   public void mapPointsArraysMismatch() {
-    new Matrix().mapPoints(new float[8], new float[9]);
+    assertThrows(Exception.class, () -> new Matrix().mapPoints(new float[8], new float[9]));
   }
 
   @Test
@@ -63,9 +64,9 @@
     assertThat(dst[0]).isEqualTo(200f);
   }
 
-  @Test(expected = Exception.class)
+  @Test
   public void mapPointsWithIndicesNull() {
-    new Matrix().mapPoints(null, 0, new float[9], 0, 1);
+    assertThrows(Exception.class, () -> new Matrix().mapPoints(null, 0, new float[9], 0, 1));
   }
 
   @Test
@@ -118,8 +119,8 @@
         .isEqualTo(new float[] {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f});
   }
 
-  @Test(expected = Exception.class)
+  @Test
   public void testSetRectToRectNull() {
-    new Matrix().setRectToRect(null, null, ScaleToFit.CENTER);
+    assertThrows(Exception.class, () -> new Matrix().setRectToRect(null, null, ScaleToFit.CENTER));
   }
 }
diff --git a/integration_tests/ctesque/src/sharedTest/java/android/text/format/TimeTest.java b/integration_tests/ctesque/src/sharedTest/java/android/text/format/TimeTest.java
index ea80cfc..0e3f989 100644
--- a/integration_tests/ctesque/src/sharedTest/java/android/text/format/TimeTest.java
+++ b/integration_tests/ctesque/src/sharedTest/java/android/text/format/TimeTest.java
@@ -5,6 +5,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
 import android.util.TimeFormatException;
@@ -220,10 +221,10 @@
     assertEquals(0, t.second);
   }
 
-  @Test(expected = TimeFormatException.class)
+  @Test
   public void shouldThrowTimeFormatException() {
     Time t = new Time();
-    t.parse("BLARGH");
+    assertThrows(TimeFormatException.class, () -> t.parse("BLARGH"));
   }
 
   @Test
diff --git a/integration_tests/ctesque/src/sharedTest/java/android/view/KeyCharacterMapTest.java b/integration_tests/ctesque/src/sharedTest/java/android/view/KeyCharacterMapTest.java
index 174335f..6924d03 100644
--- a/integration_tests/ctesque/src/sharedTest/java/android/view/KeyCharacterMapTest.java
+++ b/integration_tests/ctesque/src/sharedTest/java/android/view/KeyCharacterMapTest.java
@@ -2,6 +2,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import org.junit.Before;
@@ -32,9 +33,10 @@
     assertNotNull(keyCharacterMap);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testGetMatchNull() {
-    keyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null);
+    assertThrows(
+        IllegalArgumentException.class, () -> keyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null));
   }
 
   private int getCharacterKeyCode(char oneChar) {
@@ -44,9 +46,11 @@
     return events[0].getKeyCode();
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testGetMatchMetaStateNull() {
-    keyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null, 1);
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> keyCharacterMap.getMatch(KeyEvent.KEYCODE_0, null, 1));
   }
 
   @Test
@@ -54,9 +58,9 @@
     assertThat(keyCharacterMap.getKeyboardType()).isEqualTo(KeyCharacterMap.FULL);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testGetEventsNull() {
-    keyCharacterMap.getEvents(null);
+    assertThrows(IllegalArgumentException.class, () -> keyCharacterMap.getEvents(null));
   }
 
   @Test
diff --git a/plugins/maven-dependency-resolver/src/test/java/org/robolectric/internal/dependency/MavenDependencyResolverTest.java b/plugins/maven-dependency-resolver/src/test/java/org/robolectric/internal/dependency/MavenDependencyResolverTest.java
old mode 100755
new mode 100644
index be4b0f1..c82e41f
--- a/plugins/maven-dependency-resolver/src/test/java/org/robolectric/internal/dependency/MavenDependencyResolverTest.java
+++ b/plugins/maven-dependency-resolver/src/test/java/org/robolectric/internal/dependency/MavenDependencyResolverTest.java
@@ -1,6 +1,7 @@
 package org.robolectric.internal.dependency;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
 
 import com.google.common.hash.HashFunction;
 import com.google.common.hash.Hashing;
@@ -143,17 +144,20 @@
     assertThat(mavenArtifactFetcher.getNumRequests()).isEqualTo(0);
   }
 
-  @Test(expected = AssertionError.class)
+  @Test
   public void getLocalArtifactUrl_handlesFileNotFound() throws Exception {
     DependencyJar dependencyJar = new DependencyJar("group", "missing-artifact", "1");
-    mavenDependencyResolver.getLocalArtifactUrl(dependencyJar);
+
+    assertThrows(
+        AssertionError.class, () -> mavenDependencyResolver.getLocalArtifactUrl(dependencyJar));
   }
 
-  @Test(expected = AssertionError.class)
+  @Test
   public void getLocalArtifactUrl_handlesInvalidSha1() throws Exception {
     DependencyJar dependencyJar = new DependencyJar("group", "artifact-invalid-sha1", "1");
     addTestArtifactInvalidSha1(dependencyJar);
-    mavenDependencyResolver.getLocalArtifactUrl(dependencyJar);
+    assertThrows(
+        AssertionError.class, () -> mavenDependencyResolver.getLocalArtifactUrl(dependencyJar));
   }
 
   class TestMavenDependencyResolver extends MavenDependencyResolver {
diff --git a/resources/src/test/java/org/robolectric/manifest/MetaDataTest.java b/resources/src/test/java/org/robolectric/manifest/MetaDataTest.java
index 85752f6..aa35ba9 100644
--- a/resources/src/test/java/org/robolectric/manifest/MetaDataTest.java
+++ b/resources/src/test/java/org/robolectric/manifest/MetaDataTest.java
@@ -1,5 +1,7 @@
 package org.robolectric.manifest;
 
+import static org.junit.Assert.assertThrows;
+
 import com.google.common.collect.ImmutableList;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -27,12 +29,13 @@
     MockitoAnnotations.initMocks(this);
   }
 
-  @Test(expected = RoboNotFoundException.class)
+  @Test
   public void testNonExistantResource_throwsResourceNotFoundException() throws Exception {
     Element metaDataElement = createMetaDataNode("aName", "@xml/non_existant_resource");
 
     MetaData metaData = new MetaData(ImmutableList.<Node>of(metaDataElement));
-    metaData.init(resourceProvider, "a.package");
+
+    assertThrows(RoboNotFoundException.class, () -> metaData.init(resourceProvider, "a.package"));
   }
 
   private static Element createMetaDataNode(String name, String value) {
diff --git a/robolectric/src/test/java/org/robolectric/RobolectricTest.java b/robolectric/src/test/java/org/robolectric/RobolectricTest.java
index 9f4419b..3f78005 100644
--- a/robolectric/src/test/java/org/robolectric/RobolectricTest.java
+++ b/robolectric/src/test/java/org/robolectric/RobolectricTest.java
@@ -2,6 +2,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
@@ -36,11 +37,11 @@
 
   private Application context = ApplicationProvider.getApplicationContext();
 
-  @Test(expected = RuntimeException.class)
+  @Test
   public void clickOn_shouldThrowIfViewIsDisabled() throws Exception {
     View view = new View(context);
     view.setEnabled(false);
-    ShadowView.clickOn(view);
+    assertThrows(RuntimeException.class, () -> ShadowView.clickOn(view));
   }
 
   @Test
@@ -80,11 +81,14 @@
     verify(testOnClickListener).onClick(view);
   }
 
-  @Test(expected = ActivityNotFoundException.class)
+  @Test
   public void checkActivities_shouldSetValueOnShadowApplication() throws Exception {
     ShadowApplication.getInstance().checkActivities(true);
-    context.startActivity(
-        new Intent("i.dont.exist.activity").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+    assertThrows(
+        ActivityNotFoundException.class,
+        () ->
+            context.startActivity(
+                new Intent("i.dont.exist.activity").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)));
   }
 
   @Test
diff --git a/robolectric/src/test/java/org/robolectric/android/internal/AndroidTestEnvironmentCreateApplicationTest.java b/robolectric/src/test/java/org/robolectric/android/internal/AndroidTestEnvironmentCreateApplicationTest.java
index 24acee0..6edc428 100644
--- a/robolectric/src/test/java/org/robolectric/android/internal/AndroidTestEnvironmentCreateApplicationTest.java
+++ b/robolectric/src/test/java/org/robolectric/android/internal/AndroidTestEnvironmentCreateApplicationTest.java
@@ -2,6 +2,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 import static org.robolectric.Shadows.shadowOf;
 import static org.robolectric.android.internal.AndroidTestEnvironment.registerBroadcastReceivers;
@@ -31,11 +32,16 @@
 
   @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
 
-  @Test(expected = RuntimeException.class)
+  @Test
   public void shouldThrowWhenManifestContainsBadApplicationClassName() throws Exception {
-    AndroidTestEnvironment.createApplication(
-        newConfigWith("<application android:name=\"org.robolectric.BogusTestApplication\"/>)"),
-        null, null);
+    assertThrows(
+        RuntimeException.class,
+        () ->
+            AndroidTestEnvironment.createApplication(
+                newConfigWith(
+                    "<application android:name=\"org.robolectric.BogusTestApplication\"/>)"),
+                null,
+                null));
   }
 
   @Test
diff --git a/robolectric/src/test/java/org/robolectric/android/internal/ClassNameResolverTest.java b/robolectric/src/test/java/org/robolectric/android/internal/ClassNameResolverTest.java
index b2fc53f..c30037b 100644
--- a/robolectric/src/test/java/org/robolectric/android/internal/ClassNameResolverTest.java
+++ b/robolectric/src/test/java/org/robolectric/android/internal/ClassNameResolverTest.java
@@ -1,6 +1,7 @@
 package org.robolectric.android.internal;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -12,26 +13,38 @@
 public class ClassNameResolverTest {
   @Test
   public void shouldResolveClassesBySimpleName() throws Exception {
-    assertEquals(TestApplication.class, ClassNameResolver.resolve("org.robolectric.shadows.testing", "TestApplication"));
+    assertEquals(
+        TestApplication.class,
+        ClassNameResolver.resolve("org.robolectric.shadows.testing", "TestApplication"));
   }
 
   @Test
   public void shouldResolveClassesByDottedSimpleName() throws Exception {
-    assertEquals(TestApplication.class, ClassNameResolver.resolve("org.robolectric.shadows.testing", ".TestApplication"));
+    assertEquals(
+        TestApplication.class,
+        ClassNameResolver.resolve("org.robolectric.shadows.testing", ".TestApplication"));
   }
 
   @Test
   public void shouldResolveClassesByFullyQualifiedName() throws Exception {
-    assertEquals(TestApplication.class, ClassNameResolver.resolve("org.robolectric.shadows.testing", "org.robolectric.shadows.testing.TestApplication"));
+    assertEquals(
+        TestApplication.class,
+        ClassNameResolver.resolve(
+            "org.robolectric.shadows.testing", "org.robolectric.shadows.testing.TestApplication"));
   }
 
   @Test
   public void shouldResolveClassesByPartiallyQualifiedName() throws Exception {
-    assertEquals(TestApplication.class, ClassNameResolver.resolve("org", ".robolectric.shadows.testing.TestApplication"));
+    assertEquals(
+        TestApplication.class,
+        ClassNameResolver.resolve("org", ".robolectric.shadows.testing.TestApplication"));
   }
 
-  @Test(expected = ClassNotFoundException.class)
-  public void shouldNotResolveClassesByUndottedPartiallyQualifiedNameBecauseAndroidDoesnt() throws Exception {
-    ClassNameResolver.resolve("org", "robolectric.shadows.testing.TestApplication");
+  @Test
+  public void shouldNotResolveClassesByUndottedPartiallyQualifiedNameBecauseAndroidDoesnt()
+      throws Exception {
+    assertThrows(
+        ClassNotFoundException.class,
+        () -> ClassNameResolver.resolve("org", "robolectric.shadows.testing.TestApplication"));
   }
 }
diff --git a/robolectric/src/test/java/org/robolectric/fakes/RoboCursorTest.java b/robolectric/src/test/java/org/robolectric/fakes/RoboCursorTest.java
index ba57971..1609257 100644
--- a/robolectric/src/test/java/org/robolectric/fakes/RoboCursorTest.java
+++ b/robolectric/src/test/java/org/robolectric/fakes/RoboCursorTest.java
@@ -2,6 +2,7 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static java.util.Arrays.asList;
+import static org.junit.Assert.assertThrows;
 import static org.robolectric.Shadows.shadowOf;
 
 import android.content.ContentResolver;
@@ -48,7 +49,8 @@
 
   @Test
   public void query_shouldMakeQueryParamsAvailable() throws Exception {
-    contentResolver.query(uri, new String[]{"projection"}, "selection", new String[]{"selection"}, "sortOrder");
+    contentResolver.query(
+        uri, new String[] {"projection"}, "selection", new String[] {"selection"}, "sortOrder");
     assertThat(cursor.uri).isEqualTo(uri);
     assertThat(cursor.projection[0]).isEqualTo("projection");
     assertThat(cursor.selection).isEqualTo("selection");
@@ -144,7 +146,10 @@
 
   @Test
   public void moveToPosition_movesToAppropriateRow() throws Exception {
-    cursor.setResults(new Object[][]{new Object[]{"aString", 1234L, 41}, new Object[]{"anotherString", 5678L, 42}});
+    cursor.setResults(
+        new Object[][] {
+          new Object[] {"aString", 1234L, 41}, new Object[] {"anotherString", 5678L, 42}
+        });
 
     assertThat(cursor.moveToPosition(1)).isTrue();
     assertThat(cursor.getString(indexOf(STRING_COLUMN))).isEqualTo("anotherString");
@@ -159,14 +164,20 @@
 
   @Test
   public void moveToPosition_checksBounds() {
-    cursor.setResults(new Object[][]{new Object[]{"aString", 1234L, 41}, new Object[]{"anotherString", 5678L, 42}});
+    cursor.setResults(
+        new Object[][] {
+          new Object[] {"aString", 1234L, 41}, new Object[] {"anotherString", 5678L, 42}
+        });
     assertThat(cursor.moveToPosition(2)).isFalse();
     assertThat(cursor.moveToPosition(-1)).isFalse();
   }
 
   @Test
   public void getCount_shouldReturnNumberOfRows() {
-    cursor.setResults(new Object[][]{new Object[]{"aString", 1234L, 41}, new Object[]{"anotherString", 5678L, 42}});
+    cursor.setResults(
+        new Object[][] {
+          new Object[] {"aString", 1234L, 41}, new Object[] {"anotherString", 5678L, 42}
+        });
     assertThat(cursor.getCount()).isEqualTo(2);
   }
 
@@ -183,9 +194,10 @@
     assertThat(cursor.getColumnIndexOrThrow(STRING_COLUMN)).isEqualTo(0);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void getColumnIndexOrThrow_shouldThrowException() {
-    cursor.getColumnIndexOrThrow("invalidColumn");
+    assertThrows(
+        IllegalArgumentException.class, () -> cursor.getColumnIndexOrThrow("invalidColumn"));
   }
 
   @Test
diff --git a/robolectric/src/test/java/org/robolectric/res/ResourceRemapperTest.java b/robolectric/src/test/java/org/robolectric/res/ResourceRemapperTest.java
index 9e577de..4b0d454 100644
--- a/robolectric/src/test/java/org/robolectric/res/ResourceRemapperTest.java
+++ b/robolectric/src/test/java/org/robolectric/res/ResourceRemapperTest.java
@@ -1,6 +1,7 @@
 package org.robolectric.res;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -11,10 +12,10 @@
 @RunWith(JUnit4.class)
 public class ResourceRemapperTest {
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void forbidFinalRClasses() {
     ResourceRemapper remapper = new ResourceRemapper(null);
-    remapper.remapRClass(FinalRClass.class);
+    assertThrows(IllegalArgumentException.class, () -> remapper.remapRClass(FinalRClass.class));
   }
 
   @SuppressWarnings("TruthConstantAsserts")
diff --git a/robolectric/src/test/java/org/robolectric/res/ResourceTableTest.java b/robolectric/src/test/java/org/robolectric/res/ResourceTableTest.java
index 34e554d..6ccca64 100644
--- a/robolectric/src/test/java/org/robolectric/res/ResourceTableTest.java
+++ b/robolectric/src/test/java/org/robolectric/res/ResourceTableTest.java
@@ -1,6 +1,7 @@
 package org.robolectric.res;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertThrows;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -31,21 +32,27 @@
     assertThat(resourceTable.getPackageIdentifier()).isEqualTo(0x02);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void addResource_shouldPreventMixedPackageIdentifiers() {
     resourceTable.addResource(0x02999999, "type", "name");
-    resourceTable.addResource(0x03999999, "type", "name");
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> resourceTable.addResource(0x03999999, "type", "name"));
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void shouldForbidIdClashes() {
     resourceTable.addResource(0x02888888, "type", "name");
-    resourceTable.addResource(0x02999999, "type", "name");
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> resourceTable.addResource(0x02999999, "type", "name"));
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void shouldForbidDuplicateNames() {
     resourceTable.addResource(0x02999999, "type", "name");
-    resourceTable.addResource(0x02999999, "type", "anotherName");
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> resourceTable.addResource(0x02999999, "type", "anotherName"));
   }
 }
diff --git a/shadows/httpclient/src/test/java/org/robolectric/shadows/httpclient/ShadowDefaultRequestDirectorTest.java b/shadows/httpclient/src/test/java/org/robolectric/shadows/httpclient/ShadowDefaultRequestDirectorTest.java
index 28f083f..265919d 100644
--- a/shadows/httpclient/src/test/java/org/robolectric/shadows/httpclient/ShadowDefaultRequestDirectorTest.java
+++ b/shadows/httpclient/src/test/java/org/robolectric/shadows/httpclient/ShadowDefaultRequestDirectorTest.java
@@ -6,6 +6,7 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 import static org.robolectric.shadows.httpclient.Shadows.shadowOf;
 
@@ -390,11 +391,15 @@
     fail("Exception should have been thrown");
   }
 
-  @Test(expected = IOException.class)
+  @Test
   public void shouldSupportRealHttpRequests() throws Exception {
     FakeHttp.getFakeHttpLayer().interceptHttpRequests(false);
     DefaultHttpClient client = new DefaultHttpClient();
-    client.execute(new HttpGet("http://www.this-host-should-not-exist-123456790.org:999"));
+
+    assertThrows(
+        IOException.class,
+        () ->
+            client.execute(new HttpGet("http://www.this-host-should-not-exist-123456790.org:999")));
   }
 
   @Test
@@ -452,5 +457,4 @@
   private static String getStringContent(HttpResponse response) throws IOException {
     return CharStreams.toString(new InputStreamReader(response.getEntity().getContent(), UTF_8));
   }
-
-}
\ No newline at end of file
+}