Mercurial > hg > rhino-tests
changeset 59:700199dfbe1c draft
Make the test src/org/RhinoTests/ScriptContextClassTest.java compatible with JDK 7.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Mon, 12 Nov 2012 10:21:17 +0100 |
parents | 54e2a2055eec |
children | dc87f0d9c6b8 |
files | ChangeLog src/org/RhinoTests/ScriptContextClassTest.java |
diffstat | 2 files changed, 79 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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@redhat.com> + + * src/org/RhinoTests/ScriptContextClassTest.java: + Make this test compatible with JDK 7. + 2012-11-01 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/Reporter/HistoryPagesGenerator.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,24 @@ */ 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()", + "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[] 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()", @@ -349,6 +394,7 @@ "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 @@ -356,6 +402,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), @@ -368,7 +415,7 @@ */ protected void testGetDeclaredMethods() { // following methods should be declared - final String[] declaredMethodsThatShouldExists = { + 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()", @@ -384,6 +431,24 @@ "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),