< prev index next >

test/runtime/valhalla/nestmates/MethodHandleInheritTest.java

Print this page

        

@@ -31,10 +31,11 @@
 /*
  * @test MethodHandleInheritTest
  * @summary Verify parent's protected and private methods access from children classes using MethodHandles
  * @library /
  * @modules java.base
+ * @compile -XDdisableAccessors p2/MethodHandleSubTop.java
  * @run testng runtime.valhalla.nestmates.MethodHandleInheritTest
  */
 public class MethodHandleInheritTest {
 
     private static final String METHOD_NAME_PROTECTED = "getField";

@@ -51,53 +52,94 @@
         methodHandleSubTop = new MethodHandleSubTop();
         inner = methodHandleSubTop.new Inner();
         innerInner = inner.new InnerInner();
     }
 
+    /**
+     * negative case, to verify that there is no access to private method of the parent class from its child
+     */
     @Test(expectedExceptions = {IllegalAccessException.class})
     public void testPrivateMethodNeg() throws NoSuchMethodException, IllegalAccessException {
         methodHandleSubTop.getSuperMethodMH(METHOD_NAME_PRIVATE);
     }
 
+    /**
+     * negative case, to verify that there is no access to private field of the parent class from its child
+     */
     @Test(expectedExceptions = {IllegalAccessException.class})
     public void testPrivateFieldNeg() throws NoSuchFieldException, IllegalAccessException {
         methodHandleSubTop.getSuperFieldMH(FIELD_NAME_PRIVATE);
     }
 
-    @Test(expectedExceptions = {NoSuchMethodException.class})
-    public void testProtectedMethodFromInnerNeg() throws NoSuchMethodException, IllegalAccessException {
-        inner.getSuperMethodMH(METHOD_NAME_PROTECTED);
+    /**
+     * positive case, to verify that there is access to protected method of the parent class from its child's inner class
+     */
+    @Test
+    public void testProtectedMethodFromInnerPos() throws Throwable {
+        Assert.assertEquals((int) inner.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "inner -> top -> parent method");
     }
 
-    @Test(expectedExceptions = {NoSuchFieldException.class})
-    public void testProtectedFieldFromInnerNeg() throws NoSuchFieldException, IllegalAccessException {
-        inner.getSuperFieldMH(FIELD_NAME_PROTECTED);
+    /**
+     * positive case, to verify that there is access to protected field of the parent class from its child's inner class
+     */
+    @Test
+    public void testProtectedFieldFromInnerPos() throws Throwable {
+        Assert.assertEquals((int) inner.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "inner -> top -> parent field");
     }
 
-    @Test(expectedExceptions = {NoSuchMethodException.class})
-    public void testProtectedMethodFromInnerInnerNeg() throws NoSuchMethodException, IllegalAccessException {
-        innerInner.getSuperMethodMH(METHOD_NAME_PROTECTED);
+    /**
+     * positive case, to verify that there is access to protected method of the parent class from its child's inner inner class
+     */
+    @Test
+    public void testProtectedMethodFromInnerInnerPos() throws Throwable {
+        Assert.assertEquals((int) innerInner.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent method");
     }
 
-    @Test(expectedExceptions = {NoSuchFieldException.class})
-    public void testProtectedFieldFromInnerInnerNeg() throws NoSuchFieldException, IllegalAccessException {
-        innerInner.getSuperFieldMH(FIELD_NAME_PROTECTED);
+    /**
+     * positive case, to verify that there is access to protected field of the parent class from its child's inner inner class
+     */
+    @Test
+    public void testProtectedFieldFromInnerInnerPos() throws Throwable {
+        Assert.assertEquals((int) innerInner.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent field");
     }
 
+    /**
+     * positive case, to verify that there is access to protected field and method of the parent class from its child
+     */
     @Test
     public void testProtectedAccessFromTopPos() throws Throwable {
         Assert.assertEquals((int) methodHandleSubTop.getSuperMethodMH(METHOD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "top -> parent method");
         Assert.assertEquals((int) methodHandleSubTop.getSuperFieldMH(FIELD_NAME_PROTECTED).invokeExact(methodHandleSubTop), 1, "top -> parent field");
     }
 
-    @Test
-    public void testProtectedAccessFromInnerPos() throws Throwable {
-        Assert.assertEquals((int) inner.getSuperProtectedMethodMH().invokeExact(methodHandleSubTop), 1, "inner -> top -> parent method");
-        Assert.assertEquals((int) inner.getSuperProtectedFieldMH().invokeExact(methodHandleSubTop), 1, "inner -> top -> parent field");
+    /**
+     * negative case, to verify that there is no method access bridge in top accessing from inner
+     */
+    @Test(expectedExceptions = {NoSuchMethodException.class})
+    public void testProtectedMethodAccessFromInnerNeg() throws Throwable {
+        inner.getSuperProtectedMethodMH();
     }
 
-    @Test
-    public void testProtectedAccessFromInnerInnerPos() throws Throwable {
-        Assert.assertEquals((int) innerInner.getSuperProtectedMethodMH().invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent method");
-        Assert.assertEquals((int) innerInner.getSuperProtectedFieldMH().invokeExact(methodHandleSubTop), 1, "innerInner -> inner -> top -> parent field");
+    /**
+     * negative case, to verify that there is no field access bridge in top accessing from inner
+     */
+    @Test(expectedExceptions = {NoSuchMethodException.class})
+    public void testProtectedFieldAccessFromInnerNeg() throws Throwable {
+        inner.getSuperProtectedFieldMH();
+    }
+
+    /**
+     * negative case, to verify that there is no method access bridge in top accessing from inner's inner
+     */
+    @Test(expectedExceptions = {NoSuchMethodException.class})
+    public void testProtectedMethodAccessFromInnerInnerNeg() throws Throwable {
+        innerInner.getSuperProtectedMethodMH();
+    }
+
+    /**
+     * negative case, to verify that there is no field access bridge in top accessing from inner's inner
+     */
+    @Test(expectedExceptions = {NoSuchMethodException.class})
+    public void testProtectedFieldAccessFromInnerInnerNeg() throws Throwable {
+        innerInner.getSuperProtectedFieldMH();
     }
 }
< prev index next >