changeset 47:f7012c8427c1 draft

Make the test src/org/RhinoTests/ScriptExceptionClassTest.java compatible with JDK 7.
author Pavel Tisnovsky <ptisnovs@redhat.com>
date Fri, 05 Oct 2012 11:49:48 +0200
parents 1469d167df45
children 4f44305e5010
files ChangeLog src/org/RhinoTests/ScriptExceptionClassTest.java
diffstat 2 files changed, 66 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Oct 04 11:12:33 2012 +0200
+++ b/ChangeLog	Fri Oct 05 11:49:48 2012 +0200
@@ -1,3 +1,8 @@
+2012-10-05  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/RhinoTests/ScriptExceptionClassTest.java:
+	Make this test compatible with JDK 7.
+
 2012-10-04  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/BindingsClassTest.java:
--- a/src/org/RhinoTests/ScriptExceptionClassTest.java	Thu Oct 04 11:12:33 2012 +0200
+++ b/src/org/RhinoTests/ScriptExceptionClassTest.java	Fri Oct 05 11:49:48 2012 +0200
@@ -263,7 +263,7 @@
      * Test for method javax.script.ScriptException.getClass().getSuperclass()
      */
     protected void testGetSuperclass() {
-        Class superClass = this.scriptExceptionClass.getSuperclass();
+        Class<?> superClass = this.scriptExceptionClass.getSuperclass();
         String superClassName = superClass.getName();
         assertEquals(superClassName, "java.lang.Exception",
                 "Method ScriptException.getClass().getSuperclass() returns wrong value " + superClassName);
@@ -274,13 +274,27 @@
      */
     protected void testGetConstructors() {
         // map of constructors which should exists
-        Map<String, String> testedConstructors = new HashMap<String, String>();
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
+        Map<String, String> testedConstructors = null;
+        Map<String, String> testedConstructors_jdk6 = new HashMap<String, String>();
+        Map<String, String> testedConstructors_jdk7 = new HashMap<String, String>();
+
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
 
-        Constructor<?>[] constructors = this.scriptExceptionClass.getDeclaredConstructors();
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+        // get all constructors for this class
+        Constructor<?>[] constructors = this.scriptExceptionClass.getConstructors();
+
+        // basic check for a number of constructors
         assertEquals(constructors.length, 4, "only 4 constructors should be set");
 
         // check if all constructors exists
@@ -296,20 +310,34 @@
      * Test for method javax.script.ScriptException.getClass().getDeclaredConstructors()
      */
     protected void testGetDeclaredConstructors() {
-        // map of declared constructors which should exists
-        Map<String, String> testedConstructors = new HashMap<String, String>();
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
-        testedConstructors.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
+        // 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_jdk6.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
+        testedConstructors_jdk6.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
 
-        Constructor[] constructors = this.scriptExceptionClass.getDeclaredConstructors();
-        assertEquals(constructors.length, 4, "only 4 constructors should be set");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int,int)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String,java.lang.String,int)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.Exception)", "javax.script.ScriptException");
+        testedConstructors_jdk7.put("public javax.script.ScriptException(java.lang.String)", "javax.script.ScriptException");
+
+        // get the right map containing constructor signatures
+        testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
 
-        // check if all constructors exists
-        for (Constructor constructor : constructors) {
-            String constructorName = constructors[0].getName();
-            String constructorString = constructors[0].toString();
+        // get all declared constructors for this class
+        Constructor<?>[] declaredConstructors = this.scriptExceptionClass.getDeclaredConstructors();
+
+        // basic check for a number of declared constructors
+        assertEquals(declaredConstructors.length, 4, "only 4 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);
         }
@@ -396,6 +424,8 @@
             "public final native void java.lang.Object.notify()",
             "public final native void java.lang.Object.notifyAll()",
             "public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException",
+            "public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()",
+            "public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)",
             "public final void java.lang.Object.wait() throws java.lang.InterruptedException",
             "public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException",
             "public int javax.script.ScriptException.getColumnNumber()",
@@ -405,16 +435,14 @@
             "public java.lang.String java.lang.Throwable.toString()",
             "public java.lang.String javax.script.ScriptException.getFileName()",
             "public java.lang.String javax.script.ScriptException.getMessage()",
+            "public native int java.lang.Object.hashCode()",
+            "public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()",
             "public synchronized java.lang.Throwable java.lang.Throwable.getCause()",
-            "public native int java.lang.Object.hashCode()",
             "public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)",
-            "public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()",
             "public void java.lang.Throwable.printStackTrace()",
             "public void java.lang.Throwable.printStackTrace(java.io.PrintStream)",
             "public void java.lang.Throwable.printStackTrace(java.io.PrintWriter)",
             "public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])",
-            "public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)",
-            "public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()",
         };
 
         // get all inherited methods
@@ -437,12 +465,20 @@
      */
     protected void testGetDeclaredMethods() {
         // following methods should be declared
-        final String[] declaredMethodsThatShouldExists = {
+        final String[] declaredMethodsThatShouldExists_jdk6 = {
             "public int javax.script.ScriptException.getColumnNumber()",
             "public int javax.script.ScriptException.getLineNumber()",
             "public java.lang.String javax.script.ScriptException.getFileName()",
             "public java.lang.String javax.script.ScriptException.getMessage()",
         };
+
+        final String[] declaredMethodsThatShouldExists_jdk7 = {
+            "public int javax.script.ScriptException.getColumnNumber()",
+            "public int javax.script.ScriptException.getLineNumber()",
+            "public java.lang.String javax.script.ScriptException.getFileName()",
+            "public java.lang.String javax.script.ScriptException.getMessage()",
+        };
+
         // get all declared methods
         Method[] declaredMethods = this.scriptExceptionClass.getDeclaredMethods();
         // and transform the array into a list of method names
@@ -450,6 +486,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),