Mercurial > hg > rhino-tests
changeset 45:66320ce2a04f draft
Make the test src/org/RhinoTests/SimpleScriptContextClassTest.java compatible with JDK 7.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Wed, 03 Oct 2012 11:02:13 +0200 |
parents | fc600356b864 |
children | 1469d167df45 |
files | ChangeLog src/org/RhinoTests/SimpleScriptContextClassTest.java |
diffstat | 2 files changed, 102 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Oct 02 10:59:08 2012 +0200 +++ b/ChangeLog Wed Oct 03 11:02:13 2012 +0200 @@ -1,3 +1,8 @@ +2012-10-03 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/SimpleScriptContextClassTest.java: + Make this test compatible with JDK 7. + 2012-10-02 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/SimpleScriptContextClassTest.java:
--- a/src/org/RhinoTests/SimpleScriptContextClassTest.java Tue Oct 02 10:59:08 2012 +0200 +++ b/src/org/RhinoTests/SimpleScriptContextClassTest.java Wed Oct 03 11:02:13 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; @@ -277,32 +279,60 @@ * Test for method javax.script.SimpleScriptContext.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_jdk6.put("public javax.script.SimpleScriptContext()", "javax.script.SimpleScriptContext"); + testedConstructors_jdk7.put("public javax.script.SimpleScriptContext()", "javax.script.SimpleScriptContext"); + + // get the right map containing constructor signatures + testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7; + + // get all constructors for this class Constructor<?>[] constructors = this.simpleScriptContextClass.getConstructors(); + + // basic check for a number of constructors assertEquals(constructors.length, 1, "only one constructor should be set"); - String constructorName; - String constructorString; - constructorName = constructors[0].getName(); - constructorString = constructors[0].toString(); - assertEquals(constructorName, "javax.script.SimpleScriptContext", - "wrong constructor name " + constructorName); - assertEquals(constructorString, "public javax.script.SimpleScriptContext()", - "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.SimpleScriptContext.getClass().getDeclaredConstructors() */ protected void testGetDeclaredConstructors() { - Constructor<?>[] constructors = this.simpleScriptContextClass.getDeclaredConstructors(); - assertEquals(constructors.length, 1, "only one constructor should be set"); - String constructorName; - String constructorString; - constructorName = constructors[0].getName(); - constructorString = constructors[0].toString(); - assertEquals(constructorName, "javax.script.SimpleScriptContext", - "wrong constructor name " + constructorName); - assertEquals(constructorString, "public javax.script.SimpleScriptContext()", - "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_jdk6.put("public javax.script.SimpleScriptContext()", "javax.script.SimpleScriptContext"); + testedConstructors_jdk7.put("public javax.script.SimpleScriptContext()", "javax.script.SimpleScriptContext"); + + // get the right map containing constructor signatures + testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7; + + // get all declared constructors for this class + Constructor<?>[] declaredConstructors = this.simpleScriptContextClass.getDeclaredConstructors(); + + // basic check for a number of declared constructors + assertEquals(declaredConstructors.length, 1, "only one constructor 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); + } } /** @@ -360,7 +390,33 @@ */ protected void testGetMethods() { // following methods should be inherited - final String[] methodsThatShouldExists = { + final String[] methodsThatShouldExists_jdk6 = { + "public boolean java.lang.Object.equals(java.lang.Object)", + "public final native java.lang.Class java.lang.Object.getClass()", + "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 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.SimpleScriptContext.getAttributesScope(java.lang.String)", + "public java.io.Reader javax.script.SimpleScriptContext.getReader()", + "public java.io.Writer javax.script.SimpleScriptContext.getErrorWriter()", + "public java.io.Writer javax.script.SimpleScriptContext.getWriter()", + "public java.lang.Object javax.script.SimpleScriptContext.getAttribute(java.lang.String)", + "public java.lang.Object javax.script.SimpleScriptContext.getAttribute(java.lang.String,int)", + "public java.lang.Object javax.script.SimpleScriptContext.removeAttribute(java.lang.String,int)", + "public java.lang.String java.lang.Object.toString()", + "public java.util.List javax.script.SimpleScriptContext.getScopes()", + "public javax.script.Bindings javax.script.SimpleScriptContext.getBindings(int)", + "public native int java.lang.Object.hashCode()", + "public void javax.script.SimpleScriptContext.setAttribute(java.lang.String,java.lang.Object,int)", + "public void javax.script.SimpleScriptContext.setBindings(javax.script.Bindings,int)", + "public void javax.script.SimpleScriptContext.setErrorWriter(java.io.Writer)", + "public void javax.script.SimpleScriptContext.setReader(java.io.Reader)", + "public void javax.script.SimpleScriptContext.setWriter(java.io.Writer)", + }; + + final String[] methodsThatShouldExists_jdk7 = { "public boolean java.lang.Object.equals(java.lang.Object)", "public final native java.lang.Class java.lang.Object.getClass()", "public final native void java.lang.Object.notify()", @@ -385,6 +441,7 @@ "public void javax.script.SimpleScriptContext.setReader(java.io.Reader)", "public void javax.script.SimpleScriptContext.setWriter(java.io.Writer)", }; + // get all inherited methods Method[] methods = this.simpleScriptContextClass.getMethods(); // and transform the array into a list of method names @@ -392,6 +449,7 @@ 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), @@ -404,7 +462,7 @@ */ protected void testGetDeclaredMethods() { // following methods should be declared - final String[] declaredMethodsThatShouldExists = { + final String[] declaredMethodsThatShouldExists_jdk6 = { "public int javax.script.SimpleScriptContext.getAttributesScope(java.lang.String)", "public java.io.Reader javax.script.SimpleScriptContext.getReader()", "public java.io.Writer javax.script.SimpleScriptContext.getErrorWriter()", @@ -420,6 +478,24 @@ "public void javax.script.SimpleScriptContext.setReader(java.io.Reader)", "public void javax.script.SimpleScriptContext.setWriter(java.io.Writer)", }; + + final String[] declaredMethodsThatShouldExists_jdk7 = { + "public int javax.script.SimpleScriptContext.getAttributesScope(java.lang.String)", + "public java.io.Reader javax.script.SimpleScriptContext.getReader()", + "public java.io.Writer javax.script.SimpleScriptContext.getErrorWriter()", + "public java.io.Writer javax.script.SimpleScriptContext.getWriter()", + "public java.lang.Object javax.script.SimpleScriptContext.getAttribute(java.lang.String)", + "public java.lang.Object javax.script.SimpleScriptContext.getAttribute(java.lang.String,int)", + "public java.lang.Object javax.script.SimpleScriptContext.removeAttribute(java.lang.String,int)", + "public java.util.List javax.script.SimpleScriptContext.getScopes()", + "public javax.script.Bindings javax.script.SimpleScriptContext.getBindings(int)", + "public void javax.script.SimpleScriptContext.setAttribute(java.lang.String,java.lang.Object,int)", + "public void javax.script.SimpleScriptContext.setBindings(javax.script.Bindings,int)", + "public void javax.script.SimpleScriptContext.setErrorWriter(java.io.Writer)", + "public void javax.script.SimpleScriptContext.setReader(java.io.Reader)", + "public void javax.script.SimpleScriptContext.setWriter(java.io.Writer)", + }; + // get all declared methods Method[] declaredMethods = this.simpleScriptContextClass.getDeclaredMethods(); // and transform the array into a list of method names @@ -427,6 +503,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),