changeset 49:077761971a05 draft

Make the test src/org/RhinoTests/SimpleBindingsClassTest.java compatible with JDK 7.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Tue, 09 Oct 2012 09:18:20 +0200
parents 4f44305e5010
children 6d02300b36fa
files ChangeLog src/org/RhinoTests/SimpleBindingsClassTest.java
diffstat 2 files changed, 81 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon Oct 08 11:19:45 2012 +0200
+++ b/ChangeLog	Tue Oct 09 09:18:20 2012 +0200
@@ -1,3 +1,8 @@
+2012-10-09  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/RhinoTests/SimpleBindingsClassTest.java:
+	Make this test compatible with JDK 7.
+
 2012-10-08  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/CompilableClassTest.java:
--- a/src/org/RhinoTests/SimpleBindingsClassTest.java	Mon Oct 08 11:19:45 2012 +0200
+++ b/src/org/RhinoTests/SimpleBindingsClassTest.java	Tue Oct 09 09:18:20 2012 +0200
@@ -43,6 +43,8 @@
 import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
@@ -271,44 +273,60 @@
      * Test for method javax.script.SimpleBindings.getClass().getConstructors()
      */
     protected void testGetConstructors() {
+        // map of constructors which should exists
+        Map<String, String> testedConstructors = null;
+        Map<String, String> testedConstructors_jdk6 = new HashMap<String, String>();
+        Map<String, String> testedConstructors_jdk7 = new HashMap<String, String>();
+
+        testedConstructors_jdk7.put("public javax.script.SimpleBindings(java.util.Map)", "javax.script.SimpleBindings");
+        testedConstructors_jdk7.put("public javax.script.SimpleBindings()", "javax.script.SimpleBindings");
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+        // get all constructors for this class
         Constructor<?>[] constructors = this.simpleBindingsClass.getConstructors();
+
+        // basic check for a number of constructors
         assertEquals(constructors.length, 2, "only 2 constructors should be set");
-        String constructorName;
-        String constructorString;
-        constructorName = constructors[0].getName();
-        constructorString = constructors[0].toString();
-        assertEquals(constructorName, "javax.script.SimpleBindings",
-                "wrong constructor name " + constructorName);
-        assertEquals(constructorString, "public javax.script.SimpleBindings(java.util.Map)",
-                "wrong constructor.toString() " + constructorName);
-        constructorName = constructors[1].getName();
-        constructorString = constructors[1].toString();
-        assertEquals(constructorName, "javax.script.SimpleBindings",
-                "wrong constructor name " + constructorName);
-        assertEquals(constructorString, "public javax.script.SimpleBindings()",
-                "wrong constructor.toString() " + constructorName);
+
+        // check if all constructors exists
+        for (Constructor<?> constructor : constructors) {
+            String constructorName = constructor.getName();
+            String constructorString = constructor.toString();
+            assertTrue(testedConstructors.containsKey(constructorString), "wrong constructor.toString() " + constructorName);
+            assertEquals(testedConstructors.get(constructorString), constructorName, "wrong constructor name " + constructorName);
+        }
     }
 
     /**
      * Test for method javax.script.SimpleBindings.getClass().getDeclaredConstructors()
      */
     protected void testGetDeclaredConstructors() {
-        Constructor<?>[] constructors = this.simpleBindingsClass.getDeclaredConstructors();
-        assertEquals(constructors.length, 2, "only 2 constructors should be set");
-        String constructorName;
-        String constructorString;
-        constructorName = constructors[0].getName();
-        constructorString = constructors[0].toString();
-        assertEquals(constructorName, "javax.script.SimpleBindings",
-                "wrong constructor name " + constructorName);
-        assertEquals(constructorString, "public javax.script.SimpleBindings(java.util.Map)",
-                "wrong constructor.toString() " + constructorName);
-        constructorName = constructors[1].getName();
-        constructorString = constructors[1].toString();
-        assertEquals(constructorName, "javax.script.SimpleBindings",
-                "wrong constructor name " + constructorName);
-        assertEquals(constructorString, "public javax.script.SimpleBindings()",
-                "wrong constructor.toString() " + constructorName);
+        // map of constructors which should exists
+        Map<String, String> testedConstructors = null;
+        Map<String, String> testedConstructors_jdk6 = new HashMap<String, String>();
+        Map<String, String> testedConstructors_jdk7 = new HashMap<String, String>();
+
+        testedConstructors_jdk7.put("public javax.script.SimpleBindings(java.util.Map)", "javax.script.SimpleBindings");
+        testedConstructors_jdk7.put("public javax.script.SimpleBindings()", "javax.script.SimpleBindings");
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+        // get all declared constructors for this class
+        Constructor<?>[] declaredConstructors = this.simpleBindingsClass.getDeclaredConstructors();
+
+        // basic check for a number of declared constructors
+        assertEquals(declaredConstructors.length, 2, "only 2 constructors should be set");
+
+        // check if all declared constructors exists
+        for (Constructor<?> declaredConstructor : declaredConstructors) {
+            String constructorName = declaredConstructor.getName();
+            String constructorString = declaredConstructor.toString();
+            assertTrue(testedConstructors.containsKey(constructorString), "wrong constructor.toString() " + constructorName);
+            assertEquals(testedConstructors.get(constructorString), constructorName, "wrong constructor name " + constructorName);
+        }
     }
 
     /**
@@ -359,7 +377,10 @@
      */
     protected void testGetMethods() {
         // following methods should be inherited
-        final String[] methodsThatShouldExists = {
+        final String[] methodsThatShouldExists_jdk6 = {
+        };
+
+        final String[] methodsThatShouldExists_jdk7 = {
             "public boolean java.lang.Object.equals(java.lang.Object)",
             "public boolean javax.script.SimpleBindings.containsKey(java.lang.Object)",
             "public boolean javax.script.SimpleBindings.containsValue(java.lang.Object)",
@@ -383,6 +404,7 @@
             "public void javax.script.SimpleBindings.clear()",
             "public void javax.script.SimpleBindings.putAll(java.util.Map)",
         };
+
         // get all inherited methods
         Method[] methods = this.simpleBindingsClass.getMethods();
         // and transform the array into a list of method names
@@ -390,7 +412,24 @@
         for (Method method : methods) {
             methodsAsString.add(method.toString());
         }
+        String[] methodsThatShouldExists = getJavaVersion() < 7 ? methodsThatShouldExists_jdk6 : methodsThatShouldExists_jdk7;
         // check if all required methods really exists
+        Constructor<?>[] constructors = this.simpleBindingsClass.getDeclaredConstructors();
+        assertEquals(constructors.length, 2, "only 2 constructors should be set");
+        String constructorName;
+        String constructorString;
+        constructorName = constructors[0].getName();
+        constructorString = constructors[0].toString();
+        assertEquals(constructorName, "javax.script.SimpleBindings",
+                "wrong constructor name " + constructorName);
+        assertEquals(constructorString, "public javax.script.SimpleBindings(java.util.Map)",
+                "wrong constructor.toString() " + constructorName);
+        constructorName = constructors[1].getName();
+        constructorString = constructors[1].toString();
+        assertEquals(constructorName, "javax.script.SimpleBindings",
+                "wrong constructor name " + constructorName);
+        assertEquals(constructorString, "public javax.script.SimpleBindings()",
+                "wrong constructor.toString() " + constructorName);
         for (String methodThatShouldExists : methodsThatShouldExists) {
             assertTrue(methodsAsString.contains(methodThatShouldExists),
                     "method " + methodThatShouldExists + " not found");
@@ -402,7 +441,10 @@
      */
     protected void testGetDeclaredMethods() {
         // following methods should be declared
-        final String[] declaredMethodsThatShouldExists = {
+        final String[] declaredMethodsThatShouldExists_jdk6 = {
+        };
+
+        final String[] declaredMethodsThatShouldExists_jdk7 = {
             "private void javax.script.SimpleBindings.checkKey(java.lang.Object)",
             "public boolean javax.script.SimpleBindings.containsKey(java.lang.Object)",
             "public boolean javax.script.SimpleBindings.containsValue(java.lang.Object)",
@@ -418,6 +460,7 @@
             "public void javax.script.SimpleBindings.clear()",
             "public void javax.script.SimpleBindings.putAll(java.util.Map)",
         };
+
         // get all declared methods
         Method[] declaredMethods = this.simpleBindingsClass.getDeclaredMethods();
         // and transform the array into a list of method names
@@ -425,6 +468,7 @@
         for (Method method : declaredMethods) {
             methodsAsString.add(method.toString());
         }
+        String[] declaredMethodsThatShouldExists = getJavaVersion() < 7 ? declaredMethodsThatShouldExists_jdk6 : declaredMethodsThatShouldExists_jdk7;
         // check if all required methods really exists
         for (String methodThatShouldExists : declaredMethodsThatShouldExists) {
             assertTrue(methodsAsString.contains(methodThatShouldExists),