Use assertThrows() in OptionalMethodTest.

Cherry-picked from upstream PR #1058.

Test: m
Change-Id: Idd7b3c4ad4f6e30a1d81da534d6233b8fb4d14dc
diff --git a/common/src/test/java/org/conscrypt/metrics/OptionalMethodTest.java b/common/src/test/java/org/conscrypt/metrics/OptionalMethodTest.java
index 5e85539..eba0537 100644
--- a/common/src/test/java/org/conscrypt/metrics/OptionalMethodTest.java
+++ b/common/src/test/java/org/conscrypt/metrics/OptionalMethodTest.java
@@ -3,6 +3,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -29,9 +30,11 @@
         assertNull(substring.invoke("input", 2, 5));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void nullMethodName() {
-        new OptionalMethod(String.class, null, int.class, int.class);
+        assertThrows(
+            NullPointerException.class,
+            () -> new OptionalMethod(String.class, null, int.class, int.class));
     }
 
     @Test
diff --git a/repackaged/common/src/test/java/com/android/org/conscrypt/metrics/OptionalMethodTest.java b/repackaged/common/src/test/java/com/android/org/conscrypt/metrics/OptionalMethodTest.java
index 4675042..143a8f1 100644
--- a/repackaged/common/src/test/java/com/android/org/conscrypt/metrics/OptionalMethodTest.java
+++ b/repackaged/common/src/test/java/com/android/org/conscrypt/metrics/OptionalMethodTest.java
@@ -4,6 +4,7 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -33,9 +34,10 @@
         assertNull(substring.invoke("input", 2, 5));
     }
 
-    @Test(expected = NullPointerException.class)
+    @Test
     public void nullMethodName() {
-        new OptionalMethod(String.class, null, int.class, int.class);
+        assertThrows(NullPointerException.class,
+                () -> new OptionalMethod(String.class, null, int.class, int.class));
     }
 
     @Test