712-varhandle-invocations: add some exception helper methods

Adds helpers for when exceptions are expected from VarHandle
accessor invocations.

Bug: 206407164
Test: art/test/run-test --host 712
Change-Id: I2d9775ddc97c5709c0d3eb6e2a1dec48432bf203
diff --git a/test/712-varhandle-invocations/src/VarHandleUnitTest.java b/test/712-varhandle-invocations/src/VarHandleUnitTest.java
index 601d470..7891fa8 100644
--- a/test/712-varhandle-invocations/src/VarHandleUnitTest.java
+++ b/test/712-varhandle-invocations/src/VarHandleUnitTest.java
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+import java.lang.invoke.WrongMethodTypeException;
+
 // Base class for VarHandle unit tests for accessor operations
 public abstract class VarHandleUnitTest {
     public static VarHandleUnitTestCollector DEFAULT_COLLECTOR = new VarHandleUnitTestCollector();
@@ -93,6 +95,41 @@
         failNotEquals("Failed assertion (expected != actual)", expected, actual);
     }
 
+    interface AccessorAccess {
+        void apply() throws Exception;
+    }
+
+    void assertThrows(Class expectedException, AccessorAccess access) {
+        try {
+            access.apply();
+            fail("Expected a " + expectedException + ", but not raised");
+        } catch (Exception e) {
+            if (!expectedException.isInstance(e)) {
+                fail("Expected a " + expectedException + ", but got a " + e.getClass(), e);
+            }
+        }
+    }
+
+    public final void assertThrowsAIOBE(AccessorAccess access) {
+        assertThrows(ArrayIndexOutOfBoundsException.class, access);
+    }
+
+    public final void assertThrowsASE(AccessorAccess access) {
+        assertThrows(ArrayStoreException.class, access);
+    }
+
+    public final void assertThrowsCCE(AccessorAccess access) {
+        assertThrows(ClassCastException.class, access);
+    }
+
+    public final void assertThrowsNPE(AccessorAccess access) {
+        assertThrows(NullPointerException.class, access);
+    }
+
+    public final void assertThrowsWMTE(AccessorAccess access) {
+        assertThrows(WrongMethodTypeException.class, access);
+    }
+
     public final void failUnreachable() {
         fail("Unreachable code");
     }