Mercurial > hg > rhino-tests
changeset 48:4f44305e5010 draft
Added new functionality and made this test compatible with JDK 7:
src/org/RhinoTests/CompilableClassTest.java.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Mon, 08 Oct 2012 11:19:45 +0200 |
parents | f7012c8427c1 |
children | 077761971a05 |
files | ChangeLog src/org/RhinoTests/CompilableClassTest.java |
diffstat | 2 files changed, 54 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Oct 05 11:49:48 2012 +0200 +++ b/ChangeLog Mon Oct 08 11:19:45 2012 +0200 @@ -1,3 +1,8 @@ +2012-10-08 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/CompilableClassTest.java: + Added new functionality, made this test compatible with JDK 7. + 2012-10-05 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/ScriptExceptionClassTest.java:
--- a/src/org/RhinoTests/CompilableClassTest.java Fri Oct 05 11:49:48 2012 +0200 +++ b/src/org/RhinoTests/CompilableClassTest.java Mon Oct 08 11:19:45 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; @@ -50,7 +52,9 @@ import java.lang.reflect.Modifier; import javax.script.Compilable; +import javax.script.Invocable; import javax.script.ScriptEngineManager; +import javax.script.ScriptEngine; @@ -91,7 +95,7 @@ * Test for method javax.script.Compilable.getClass().isInstance() */ protected void testIsInstance() { - assertTrue(this.compilableClass.isInstance((new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript))), + assertTrue(this.compilableClass.isInstance((Compilable)(new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript))), "Method Compilable.getClass().isInstance() returns wrong value"); } @@ -270,16 +274,42 @@ * Test for method javax.script.Compilable.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>(); + + + // get the right map containing constructor signatures + testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7; + + // get all constructors for this class Constructor<?>[] constructors = this.compilableClass.getConstructors(); + + // basic check for a number of constructors assertEquals(constructors.length, 0, "no constructors should be set"); + } /** * Test for method javax.script.Compilable.getClass().getDeclaredConstructors() */ protected void testGetDeclaredConstructors() { - Constructor<?>[] constructors = this.compilableClass.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.compilableClass.getDeclaredConstructors(); + + // basic check for a number of declared constructors + assertEquals(declaredConstructors.length, 0, "no constructors should be set"); + } /** @@ -329,10 +359,16 @@ */ protected void testGetMethods() { // following methods should be inherited - final String[] methodsThatShouldExists = { + final String[] methodsThatShouldExists_jdk6 = { "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.io.Reader) throws javax.script.ScriptException", "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.lang.String) throws javax.script.ScriptException", }; + + final String[] methodsThatShouldExists_jdk7 = { + "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.io.Reader) throws javax.script.ScriptException", + "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.lang.String) throws javax.script.ScriptException", + }; + // get all inherited methods Method[] methods = this.compilableClass.getMethods(); // and transform the array into a list of method names @@ -340,6 +376,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), @@ -352,10 +389,16 @@ */ protected void testGetDeclaredMethods() { // following methods should be declared - final String[] declaredMethodsThatShouldExists = { + final String[] declaredMethodsThatShouldExists_jdk6 = { "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.io.Reader) throws javax.script.ScriptException", "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.lang.String) throws javax.script.ScriptException", }; + + final String[] declaredMethodsThatShouldExists_jdk7 = { + "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.io.Reader) throws javax.script.ScriptException", + "public abstract javax.script.CompiledScript javax.script.Compilable.compile(java.lang.String) throws javax.script.ScriptException", + }; + // get all declared methods Method[] declaredMethods = this.compilableClass.getDeclaredMethods(); // and transform the array into a list of method names @@ -363,6 +406,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),