/hg/rhino-tests: Make the test src/org/RhinoTests/ScriptContextC...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Mon Nov 12 01:18:21 PST 2012


changeset 700199dfbe1c in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=700199dfbe1c
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Nov 12 10:21:17 2012 +0100

	Make the test src/org/RhinoTests/ScriptContextClassTest.java compatible with JDK 7.


diffstat:

 ChangeLog                                      |    5 +
 src/org/RhinoTests/ScriptContextClassTest.java |  118 +++++++++++++++++++-----
 2 files changed, 97 insertions(+), 26 deletions(-)

diffs (204 lines):

diff -r 54e2a2055eec -r 700199dfbe1c ChangeLog
--- a/ChangeLog	Thu Nov 01 10:23:59 2012 +0100
+++ b/ChangeLog	Mon Nov 12 10:21:17 2012 +0100
@@ -1,3 +1,8 @@
+2012-11-12  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/ScriptContextClassTest.java:
+	Make this test compatible with JDK 7.
+
 2012-11-01  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/Reporter/HistoryPagesGenerator.java:
diff -r 54e2a2055eec -r 700199dfbe1c src/org/RhinoTests/ScriptContextClassTest.java
--- a/src/org/RhinoTests/ScriptContextClassTest.java	Thu Nov 01 10:23:59 2012 +0100
+++ b/src/org/RhinoTests/ScriptContextClassTest.java	Mon Nov 12 10:21:17 2012 +0100
@@ -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;
@@ -65,7 +67,7 @@
     /**
      * Object that represents the type of ScriptContext.
      */
-    Class scriptContextClass = null;
+    Class<?> scriptContextClass = null;
 
     @Override
     protected void setUp(String[] args) {
@@ -193,7 +195,7 @@
      * Test for method javax.script.ScriptContext.getClass().getInterfaces()
      */
     protected void testGetInterfaces() {
-        List interfaces = Arrays.asList(this.scriptContextClass.getInterfaces());
+        List<Class<?>> interfaces = Arrays.asList(this.scriptContextClass.getInterfaces());
         assertTrue(interfaces.isEmpty(),
                 "list of implemented interfaces should be empty");
     }
@@ -261,7 +263,7 @@
      * Test for method javax.script.ScriptContext.getClass().getSuperclass()
      */
     protected void testGetSuperclass() {
-        Class superClass = this.scriptContextClass.getSuperclass();
+        Class<?> superClass = this.scriptContextClass.getSuperclass();
         assertNull(superClass,
                 "Method ScriptContext.getClass().getSuperclass() does not return null");
     }
@@ -270,16 +272,42 @@
      * Test for method javax.script.ScriptContext.getClass().getConstructors()
      */
     protected void testGetConstructors() {
-        Constructor[] constructors = this.scriptContextClass.getConstructors();
+        // 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>();
+
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+        // get all constructors for this class
+        Constructor<?>[] constructors = this.scriptContextClass.getConstructors();
+
+        // basic check for a number of constructors
         assertEquals(constructors.length, 0, "no constructors should be set");
+
     }
 
     /**
      * Test for method javax.script.ScriptContext.getClass().getDeclaredConstructors()
      */
     protected void testGetDeclaredConstructors() {
-        Constructor[] constructors = this.scriptContextClass.getDeclaredConstructors();
-        assertEquals(constructors.length, 0, "no constructors should be set");
+        // 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>();
+
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+        // get all declared constructors for this class
+        Constructor<?>[] declaredConstructors = this.scriptContextClass.getDeclaredConstructors();
+
+        // basic check for a number of declared constructors
+        assertEquals(declaredConstructors.length, 0, "no constructors should be set");
+
     }
 
     /**
@@ -333,7 +361,7 @@
      */
     protected void testGetMethods() {
         // following methods should be inherited
-        final String[] methodsThatShouldExists = {
+        final String[] methodsThatShouldExists_jdk6 = {
             "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
             "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
             "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
@@ -349,26 +377,8 @@
             "public abstract void javax.script.ScriptContext.setReader(java.io.Reader)",
             "public abstract void javax.script.ScriptContext.setWriter(java.io.Writer)",
         };
-        // get all inherited methods
-        Method[] methods = this.scriptContextClass.getMethods();
-        // and transform the array into a list of method names
-        List<String> methodsAsString = new ArrayList<String>();
-        for (Method method : methods) {
-            methodsAsString.add(method.toString());
-        }
-        // check if all required methods really exists
-        for (String methodThatShouldExists : methodsThatShouldExists) {
-            assertTrue(methodsAsString.contains(methodThatShouldExists),
-                    "method " + methodThatShouldExists + " not found");
-        }
-    }
 
-    /**
-     * Test for method javax.script.ScriptContext.getClass().getDeclaredMethods()
-     */
-    protected void testGetDeclaredMethods() {
-        // following methods should be declared
-        final String[] declaredMethodsThatShouldExists = {
+        final String[] methodsThatShouldExists_jdk7 = {
             "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
             "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
             "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
@@ -384,6 +394,61 @@
             "public abstract void javax.script.ScriptContext.setReader(java.io.Reader)",
             "public abstract void javax.script.ScriptContext.setWriter(java.io.Writer)",
         };
+
+        // get all inherited methods
+        Method[] methods = this.scriptContextClass.getMethods();
+        // and transform the array into a list of method names
+        List<String> methodsAsString = new ArrayList<String>();
+        for (Method method : methods) {
+            methodsAsString.add(method.toString());
+        }
+        String[] methodsThatShouldExists = getJavaVersion() < 7 ? methodsThatShouldExists_jdk6 : methodsThatShouldExists_jdk7;
+        // check if all required methods really exists
+        for (String methodThatShouldExists : methodsThatShouldExists) {
+            assertTrue(methodsAsString.contains(methodThatShouldExists),
+                    "method " + methodThatShouldExists + " not found");
+        }
+    }
+
+    /**
+     * Test for method javax.script.ScriptContext.getClass().getDeclaredMethods()
+     */
+    protected void testGetDeclaredMethods() {
+        // following methods should be declared
+        final String[] declaredMethodsThatShouldExists_jdk6 = {
+            "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+            "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
+            "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
+            "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
+            "public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String)",
+            "public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String,int)",
+            "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
+            "public abstract java.util.List javax.script.ScriptContext.getScopes()",
+            "public abstract javax.script.Bindings javax.script.ScriptContext.getBindings(int)",
+            "public abstract void javax.script.ScriptContext.setAttribute(java.lang.String,java.lang.Object,int)",
+            "public abstract void javax.script.ScriptContext.setBindings(javax.script.Bindings,int)",
+            "public abstract void javax.script.ScriptContext.setErrorWriter(java.io.Writer)",
+            "public abstract void javax.script.ScriptContext.setReader(java.io.Reader)",
+            "public abstract void javax.script.ScriptContext.setWriter(java.io.Writer)",
+        };
+
+        final String[] declaredMethodsThatShouldExists_jdk7 = {
+            "public abstract int javax.script.ScriptContext.getAttributesScope(java.lang.String)",
+            "public abstract java.io.Reader javax.script.ScriptContext.getReader()",
+            "public abstract java.io.Writer javax.script.ScriptContext.getErrorWriter()",
+            "public abstract java.io.Writer javax.script.ScriptContext.getWriter()",
+            "public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String)",
+            "public abstract java.lang.Object javax.script.ScriptContext.getAttribute(java.lang.String,int)",
+            "public abstract java.lang.Object javax.script.ScriptContext.removeAttribute(java.lang.String,int)",
+            "public abstract java.util.List javax.script.ScriptContext.getScopes()",
+            "public abstract javax.script.Bindings javax.script.ScriptContext.getBindings(int)",
+            "public abstract void javax.script.ScriptContext.setAttribute(java.lang.String,java.lang.Object,int)",
+            "public abstract void javax.script.ScriptContext.setBindings(javax.script.Bindings,int)",
+            "public abstract void javax.script.ScriptContext.setErrorWriter(java.io.Writer)",
+            "public abstract void javax.script.ScriptContext.setReader(java.io.Reader)",
+            "public abstract void javax.script.ScriptContext.setWriter(java.io.Writer)",
+        };
+
         // get all declared methods
         Method[] declaredMethods = this.scriptContextClass.getDeclaredMethods();
         // and transform the array into a list of method names
@@ -391,6 +456,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),



More information about the distro-pkg-dev mailing list