changeset 50732:f7d2d1cc9d8c jep-334

additional unit tests for ClassDesc
author vromero
date Wed, 23 May 2018 13:33:44 -0700
parents 38d5f419e20c
children acd4969ec1f8 affc14961831
files test/jdk/java/lang/invoke/constant/ClassRefTest.java
diffstat 1 files changed, 30 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/java/lang/invoke/constant/ClassRefTest.java	Wed May 23 11:09:31 2018 -0700
+++ b/test/jdk/java/lang/invoke/constant/ClassRefTest.java	Wed May 23 13:33:44 2018 -0700
@@ -46,7 +46,7 @@
  * @test
  * @compile -XDfolding=false ClassRefTest.java
  * @run testng ClassRefTest
- * @summary unit tests for java.lang.invoke.constant.ClassRef
+ * @summary unit tests for java.lang.invoke.constant.ClassDesc
  */
 @Test
 public class ClassRefTest extends SymbolicRefTest {
@@ -160,8 +160,7 @@
         try {
             cr.packageName();
             fail("");
-        }
-        catch (IllegalStateException e) {
+        } catch (IllegalStateException e) {
             // good
         }
     }
@@ -178,6 +177,15 @@
         testBadPackageName(ClassDesc.of("Bar").arrayType());
     }
 
+    private void testBadArrayRank(ClassDesc cr) {
+        try {
+            cr.arrayType(-1);
+            fail("");
+        } catch (IllegalArgumentException e) {
+            // good
+        }
+    }
+
     public void testArrayClassRef() throws ReflectiveOperationException {
         for (String d : basicDescs) {
             ClassDesc a0 = ClassDesc.ofDescriptor(d);
@@ -208,6 +216,10 @@
             assertEquals(classToDescriptor(a0.resolveConstantDesc(LOOKUP)), a0.descriptorString());
             assertEquals(classToDescriptor(a1.resolveConstantDesc(LOOKUP)), a1.descriptorString());
             assertEquals(classToDescriptor(a2.resolveConstantDesc(LOOKUP)), a2.descriptorString());
+
+            testBadArrayRank(ConstantDescs.CR_int);
+            testBadArrayRank(ConstantDescs.CR_String);
+            testBadArrayRank(ClassDesc.of("Bar"));
         }
     }
 
@@ -225,5 +237,20 @@
                 // good
             }
         }
+
+        ClassDesc barDesc = ClassDesc.of("Bar");
+        for (Primitives p : Primitives.values()) {
+            testBadInnerClasses(ClassDesc.ofDescriptor(p.descriptor), "any");
+            testBadInnerClasses(ClassDesc.ofDescriptor(p.descriptor), "any", "other");
+        }
+    }
+
+    private void testBadInnerClasses(ClassDesc cr, String firstInnerName, String... moreInnerNames) {
+        try {
+            cr.inner(firstInnerName, moreInnerNames);
+            fail("");
+        } catch (IllegalStateException e) {
+            // good
+        }
     }
 }