diff options
author | 2021-11-28 21:00:37 +0000 | |
---|---|---|
committer | 2021-11-29 14:46:57 +0000 | |
commit | 8b910bce95d2a1dbd3930f39dd10dfdde397b0da (patch) | |
tree | 462749153e9d2899aa665e27bda85bbc536095fc | |
parent | 9e598907f28277b0f0e3dcd725d6ed9d71f8a958 (diff) |
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
-rw-r--r-- | test/712-varhandle-invocations/src/VarHandleUnitTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/712-varhandle-invocations/src/VarHandleUnitTest.java b/test/712-varhandle-invocations/src/VarHandleUnitTest.java index 601d470950..7891fa8db0 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 @@ public abstract class VarHandleUnitTest { 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"); } |