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

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Wed Nov 14 02:02:38 PST 2012


changeset 39454ef51d62 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=39454ef51d62
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Nov 14 11:05:35 2012 +0100

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


diffstat:

 ChangeLog                                     |    5 +
 src/org/RhinoTests/ScriptEngineClassTest.java |  119 ++++++++++++++++++++-----
 2 files changed, 98 insertions(+), 26 deletions(-)

diffs (212 lines):

diff -r dc87f0d9c6b8 -r 39454ef51d62 ChangeLog
--- a/ChangeLog	Tue Nov 13 11:14:14 2012 +0100
+++ b/ChangeLog	Wed Nov 14 11:05:35 2012 +0100
@@ -1,3 +1,8 @@
+2012-11-14  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/ScriptEngineClassTest.java:
+	Make this test compatible with JDK 7.
+
 2012-11-13  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/ScriptEngineManagerClassTest.java:
diff -r dc87f0d9c6b8 -r 39454ef51d62 src/org/RhinoTests/ScriptEngineClassTest.java
--- a/src/org/RhinoTests/ScriptEngineClassTest.java	Tue Nov 13 11:14:14 2012 +0100
+++ b/src/org/RhinoTests/ScriptEngineClassTest.java	Wed Nov 14 11:05:35 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;
@@ -51,6 +53,7 @@
 
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
+import javax.script.ScriptEngine;
 
 
 
@@ -65,7 +68,7 @@
     /**
      * Object that represents the type of ScriptEngine.
      */
-    Class scriptEngineClass = null;
+    Class<?> scriptEngineClass = null;
 
     @Override
     protected void setUp(String[] args) {
@@ -193,7 +196,7 @@
      * Test for method javax.script.ScriptEngine.getClass().getInterfaces()
      */
     protected void testGetInterfaces() {
-        List interfaces = Arrays.asList(this.scriptEngineClass.getInterfaces());
+        List<Class<?>> interfaces = Arrays.asList(this.scriptEngineClass.getInterfaces());
         assertTrue(interfaces.isEmpty(),
                 "list of implemented interfaces should be empty");
     }
@@ -261,7 +264,7 @@
      * Test for method javax.script.ScriptEngine.getClass().getSuperclass()
      */
     protected void testGetSuperclass() {
-        Class superClass = this.scriptEngineClass.getSuperclass();
+        Class<?> superClass = this.scriptEngineClass.getSuperclass();
         assertNull(superClass,
                 "Method ScriptEngine.getClass().getSuperclass() does not return null");
     }
@@ -270,16 +273,42 @@
      * Test for method javax.script.ScriptEngine.getClass().getConstructors()
      */
     protected void testGetConstructors() {
-        Constructor[] constructors = this.scriptEngineClass.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.scriptEngineClass.getConstructors();
+
+        // basic check for a number of constructors
         assertEquals(constructors.length, 0, "no constructors should be set");
+
     }
 
     /**
      * Test for method javax.script.ScriptEngine.getClass().getDeclaredConstructors()
      */
     protected void testGetDeclaredConstructors() {
-        Constructor[] constructors = this.scriptEngineClass.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.scriptEngineClass.getDeclaredConstructors();
+
+        // basic check for a number of declared constructors
+        assertEquals(declaredConstructors.length, 0, "no constructors should be set");
+
     }
 
     /**
@@ -343,7 +372,7 @@
      */
     protected void testGetMethods() {
         // following methods should be inherited
-        final String[] methodsThatShouldExists = {
+        final String[] methodsThatShouldExists_jdk6 = {
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
@@ -359,26 +388,8 @@
             "public abstract void javax.script.ScriptEngine.setBindings(javax.script.Bindings,int)",
             "public abstract void javax.script.ScriptEngine.setContext(javax.script.ScriptContext)",
         };
-        // get all inherited methods
-        Method[] methods = this.scriptEngineClass.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.ScriptEngine.getClass().getDeclaredMethods()
-     */
-    protected void testGetDeclaredMethods() {
-        // following methods should be declared
-        final String[] declaredMethodsThatShouldExists = {
+        final String[] methodsThatShouldExists_jdk7 = {
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
             "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
@@ -394,6 +405,61 @@
             "public abstract void javax.script.ScriptEngine.setBindings(javax.script.Bindings,int)",
             "public abstract void javax.script.ScriptEngine.setContext(javax.script.ScriptContext)",
         };
+
+        // get all inherited methods
+        Method[] methods = this.scriptEngineClass.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.ScriptEngine.getClass().getDeclaredMethods()
+     */
+    protected void testGetDeclaredMethods() {
+        // following methods should be declared
+        final String[] declaredMethodsThatShouldExists_jdk6 = {
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.Bindings) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.ScriptContext) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.get(java.lang.String)",
+            "public abstract javax.script.Bindings javax.script.ScriptEngine.createBindings()",
+            "public abstract javax.script.Bindings javax.script.ScriptEngine.getBindings(int)",
+            "public abstract javax.script.ScriptContext javax.script.ScriptEngine.getContext()",
+            "public abstract javax.script.ScriptEngineFactory javax.script.ScriptEngine.getFactory()",
+            "public abstract void javax.script.ScriptEngine.put(java.lang.String,java.lang.Object)",
+            "public abstract void javax.script.ScriptEngine.setBindings(javax.script.Bindings,int)",
+            "public abstract void javax.script.ScriptEngine.setContext(javax.script.ScriptContext)",
+        };
+
+        final String[] declaredMethodsThatShouldExists_jdk7 = {
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.Bindings) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.ScriptContext) throws javax.script.ScriptException",
+            "public abstract java.lang.Object javax.script.ScriptEngine.get(java.lang.String)",
+            "public abstract javax.script.Bindings javax.script.ScriptEngine.createBindings()",
+            "public abstract javax.script.Bindings javax.script.ScriptEngine.getBindings(int)",
+            "public abstract javax.script.ScriptContext javax.script.ScriptEngine.getContext()",
+            "public abstract javax.script.ScriptEngineFactory javax.script.ScriptEngine.getFactory()",
+            "public abstract void javax.script.ScriptEngine.put(java.lang.String,java.lang.Object)",
+            "public abstract void javax.script.ScriptEngine.setBindings(javax.script.Bindings,int)",
+            "public abstract void javax.script.ScriptEngine.setContext(javax.script.ScriptContext)",
+        };
+
         // get all declared methods
         Method[] declaredMethods = this.scriptEngineClass.getDeclaredMethods();
         // and transform the array into a list of method names
@@ -401,6 +467,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