use of examples.PackageExamples in project openj9 by eclipse.
the class Unreflect_InvokeTracker method test_Unreflect_Public_CrossPackage_SuperClass.
/**
* unreflect a super class method using a subclass lookup, parent child in different packages.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
@SuppressWarnings({ "unchecked", "rawtypes" })
public void test_Unreflect_Public_CrossPackage_SuperClass() throws Throwable {
Class clazz = Class.forName("examples.PackageExamples");
Method parentMethod = clazz.getDeclaredMethod("addPublic", int.class, int.class);
Lookup childLookup = CrossPackageExampleSubclass.getLookup();
MethodHandle mh = childLookup.unreflect(parentMethod);
PackageExamples g = new PackageExamples();
int out = (int) mh.invokeExact(g, 1, 2);
AssertJUnit.assertEquals(3, out);
}
use of examples.PackageExamples in project openj9 by eclipse.
the class Unreflect_InvokeTracker method test_Unreflect_Protected_CrossPackage_Overridden.
/**
* Test to unreflect a protected overridden method belonging to a different package than the Lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_Unreflect_Protected_CrossPackage_Overridden() throws Throwable {
Class clazz = Class.forName("com.ibm.j9.jsr292.CrossPackageExampleSubclass");
Method m = clazz.getDeclaredMethod("addProtected", int.class, int.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
PackageExamples g = new CrossPackageExampleSubclass();
int out = (int) mh.invoke(g, 1, 2);
AssertJUnit.assertEquals(-1, out);
}
use of examples.PackageExamples in project openj9 by eclipse.
the class Unreflect_InvokeTracker method test_Unreflect_Public_CrossPackage_Overridden.
/**
* Test to unreflect a public overridden method belonging to a different package than the Lookup class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
@SuppressWarnings({ "rawtypes", "unchecked" })
public void test_Unreflect_Public_CrossPackage_Overridden() throws Throwable {
Class clazz = Class.forName("com.ibm.j9.jsr292.CrossPackageExampleSubclass");
Method m = clazz.getDeclaredMethod("addPublic", int.class, int.class);
MethodHandle mh = MethodHandles.lookup().unreflect(m);
PackageExamples g = new CrossPackageExampleSubclass();
int out = (int) mh.invoke(g, 1, 2);
AssertJUnit.assertEquals(5, out);
}
use of examples.PackageExamples in project openj9 by eclipse.
the class Find_InvokeTracker method test_GetterSetter_Public_CrossPackage_SubclassLookup.
/**
* findSetter, findGetter tests using a sub-class as lookup class and public fields
* belonging to the super-class under a different package than the lookup ( sub ) class.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_GetterSetter_Public_CrossPackage_SubclassLookup() throws Throwable {
Lookup subclassLookup = CrossPackageExampleSubclass.getLookup();
MethodHandle mhSetter = subclassLookup.findSetter(PackageExamples.class, "nonStaticPublicField", int.class);
MethodHandle mhGetter = subclassLookup.findGetter(PackageExamples.class, "nonStaticPublicField", int.class);
PackageExamples g = new PackageExamples();
mhSetter.invokeExact(g, 5);
int o = (int) mhGetter.invoke(g);
AssertJUnit.assertEquals(o, 5);
}
use of examples.PackageExamples in project openj9 by eclipse.
the class HelperConstructorClass method test_asVarargsCollector_CrossPackage_Virtual_WrongType.
/**
* Negative test : asVarargsCollector test using wrong type and a virtual method belonging to a class in a different package
* @throws Throwable
*/
@Test(expectedExceptions = IllegalArgumentException.class, groups = { "level.extended" })
public void test_asVarargsCollector_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.asVarargsCollector(int[].class);
Assert.fail("The test case failed to throw an IllegalArgumentException in the case of the wrong method type");
}
Aggregations