Java Code Examples for java.lang.invoke.MethodHandles#tryFinally()

The following examples show how to use java.lang.invoke.MethodHandles#tryFinally() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TryFinallyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "negativeTestData")
public static void testTryFinallyNegative(MethodHandle target, MethodHandle cleanup, String expectedMessage) {
    boolean caught = false;
    try {
        MethodHandles.tryFinally(target, cleanup);
    } catch (IllegalArgumentException iae) {
        assertEquals(expectedMessage, iae.getMessage());
        caught = true;
    }
    assertTrue(caught);
}
 
Example 2
Source File: TryFinallyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public static void testTryFinally() throws Throwable {
    MethodHandle hello = MethodHandles.tryFinally(TryFinally.MH_greet, TryFinally.MH_exclaim);
    assertEquals(TryFinally.MT_hello, hello.type());
    assertEquals("Hello, world!", hello.invoke("world"));
}
 
Example 3
Source File: TryFinallyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public static void testTryFinallyVoid() throws Throwable {
    MethodHandle tfVoid = MethodHandles.tryFinally(TryFinally.MH_print, TryFinally.MH_printMore);
    assertEquals(TryFinally.MT_printHello, tfVoid.type());
    tfVoid.invoke("world");
}
 
Example 4
Source File: TryFinallyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public static void testTryFinallySublist() throws Throwable {
    MethodHandle helloMore = MethodHandles.tryFinally(TryFinally.MH_greetMore, TryFinally.MH_exclaimMore);
    assertEquals(TryFinally.MT_moreHello, helloMore.type());
    assertEquals("Hello, world and universe (but world first)!", helloMore.invoke("world", "universe"));
}
 
Example 5
Source File: TryFinallyTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider = "omitTrailingArguments")
public static void testTryFinallyOmitTrailingArguments(MethodHandle cleanup) throws Throwable {
    MethodHandle tf = MethodHandles.tryFinally(TryFinally.MH_dummyTarget, cleanup);
    tf.invoke(1, 2L, "a", 23, 42L, "b");
}