use of examples.PackageExamples in project openj9 by eclipse.
the class MethodHandleProxiesTest method test_wrapperInstanceType_NegativeTest.
/**
* Negative test for wrapperInstanceType using non-wrapper types
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_wrapperInstanceType_NegativeTest() throws Throwable {
boolean notAWrapperInstance = false;
try {
Class<?> retrievedTargetType = MethodHandleProxies.wrapperInstanceType(new PackageExamples());
AssertJUnit.assertEquals(SamePackageSingleMethodInterfaceExample.class, retrievedTargetType);
} catch (IllegalArgumentException e) {
notAWrapperInstance = true;
}
AssertJUnit.assertTrue(notAWrapperInstance);
}
use of examples.PackageExamples in project openj9 by eclipse.
the class HelperConstructorClass method test_asVarargsCollector_SamePackage_Virtual_WrongType.
/**
* Negative test : asVarargsCollector test using wrong method type
* @throws Throwable
*/
@Test(expectedExceptions = IllegalArgumentException.class, groups = { "level.extended" })
public void test_asVarargsCollector_SamePackage_Virtual_WrongType() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findVirtual(PackageExamples.class, "getLength", MethodType.methodType(int.class, String[].class));
PackageExamples g = new PackageExamples();
mh = mh.bindTo(g);
mh = mh.asVarargsCollector(int[].class);
Assert.fail("The test case failed to throw an IllegalArgumentException in the case of the wrong method type");
}
use of examples.PackageExamples in project openj9 by eclipse.
the class HelperConstructorClass method test_asSpreader_CrossPackage_Virtual_WrongType.
/**
* Negative test : asSpreader test using cross package virtual method with a wrong method type
* @throws Throwable
*/
@Test(expectedExceptions = WrongMethodTypeException.class, groups = { "level.extended" })
public void test_asSpreader_CrossPackage_Virtual_WrongType() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findVirtual(PackageExamples.class, "addPublic", MethodType.methodType(int.class, int.class, int.class));
PackageExamples g = new PackageExamples();
mh = mh.bindTo(g);
mh = mh.asSpreader(String[].class, 2);
Assert.fail("The test case failed to throw an WrongMethodTypeException in the case of the wrong method type");
}
use of examples.PackageExamples in project openj9 by eclipse.
the class HelperConstructorClass method test_asCollector_CrossPackage_Virtual_WrongType.
/**
* Negative test : asCollector using wrong type on a MH obtained through a findVirtual call to a class in a different package
* @throws Throwable
*/
@Test(expectedExceptions = IllegalArgumentException.class, groups = { "level.extended" })
public void test_asCollector_CrossPackage_Virtual_WrongType() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findVirtual(PackageExamples.class, "getLength", MethodType.methodType(int.class, String[].class));
PackageExamples g = new PackageExamples();
mh = mh.bindTo(g);
mh = mh.asCollector(int[].class, 2);
Assert.fail("The test case failed to throw an IllegalArgumentException in the case of the wrong method type");
}
use of examples.PackageExamples in project openj9 by eclipse.
the class HelperConstructorClass method test_asVarargsCollector_CrossPackage_Virtual_Invoke.
/**
* Basic asVarargsCollector test using a virtual method in a class living in a different package (uses MethodHandle.invoke)
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_asVarargsCollector_CrossPackage_Virtual_Invoke() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findVirtual(PackageExamples.class, "getLength", MethodType.methodType(int.class, String[].class));
PackageExamples g = new PackageExamples();
mh = mh.bindTo(g);
mh = mh.asVarargsCollector(String[].class);
Assert.assertEquals(mh.type(), MethodType.methodType(int.class, String[].class));
Assert.assertEquals(mh.invoke("A", "star", "I am looking at", "may already have", "died", "long ago"), 6);
}
Aggregations