Mercurial > hg > rhino-tests
changeset 53:a34c578cc02b draft
Make the test src/org/RhinoTests/InvocableClassTest.java compatible with JDK 7.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Mon, 15 Oct 2012 14:44:52 +0200 |
parents | abe703a3501c |
children | 0a793f171324 |
files | ChangeLog src/org/RhinoTests/InvocableClassTest.java |
diffstat | 2 files changed, 60 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Fri Oct 12 09:27:16 2012 +0200 +++ b/ChangeLog Mon Oct 15 14:44:52 2012 +0200 @@ -1,3 +1,8 @@ +2012-10-15 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/InvocableClassTest.java: + Make this test compatible with JDK 7. + 2012-10-12 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/InvocableClassTest.java:
--- a/src/org/RhinoTests/InvocableClassTest.java Fri Oct 12 09:27:16 2012 +0200 +++ b/src/org/RhinoTests/InvocableClassTest.java Mon Oct 15 14:44:52 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; @@ -66,7 +68,7 @@ /** * Object that represents the type of Invocable. */ - Class invocableClass = null; + Class<?> invocableClass = null; @Override protected void setUp(String[] args) { @@ -194,7 +196,7 @@ * Test for method javax.script.Invocable.getClass().getInterfaces() */ protected void testGetInterfaces() { - List interfaces = Arrays.asList(this.invocableClass.getInterfaces()); + List<Class<?>> interfaces = Arrays.asList(this.invocableClass.getInterfaces()); assertTrue(interfaces.isEmpty(), "list of implemented interfaces should be empty"); } @@ -262,7 +264,7 @@ * Test for method javax.script.Invocable.getClass().getSuperclass() */ protected void testGetSuperclass() { - Class superClass = this.invocableClass.getSuperclass(); + Class<?> superClass = this.invocableClass.getSuperclass(); assertNull(superClass, "Method Invocable.getClass().getSuperclass() does not return null"); } @@ -271,16 +273,42 @@ * Test for method javax.script.Invocable.getClass().getConstructors() */ protected void testGetConstructors() { - Constructor[] constructors = this.invocableClass.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.invocableClass.getConstructors(); + + // basic check for a number of constructors assertEquals(constructors.length, 0, "no constructors should be set"); + } /** * Test for method javax.script.Invocable.getClass().getDeclaredConstructors() */ protected void testGetDeclaredConstructors() { - Constructor[] constructors = this.invocableClass.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.invocableClass.getDeclaredConstructors(); + + // basic check for a number of declared constructors + assertEquals(declaredConstructors.length, 0, "no constructors should be set"); + } /** @@ -330,12 +358,20 @@ */ protected void testGetMethods() { // following methods should be inherited - final String[] methodsThatShouldExists = { + final String[] methodsThatShouldExists_jdk6 = { "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)", "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)", "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", }; + + final String[] methodsThatShouldExists_jdk7 = { + "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)", + "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)", + "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", + "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", + }; + // get all inherited methods Method[] methods = this.invocableClass.getMethods(); // and transform the array into a list of method names @@ -343,6 +379,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), @@ -355,12 +392,20 @@ */ protected void testGetDeclaredMethods() { // following methods should be declared - final String[] declaredMethodsThatShouldExists = { + final String[] declaredMethodsThatShouldExists_jdk6 = { "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)", "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)", "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", }; + + final String[] declaredMethodsThatShouldExists_jdk7 = { + "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Class)", + "public abstract java.lang.Object javax.script.Invocable.getInterface(java.lang.Object,java.lang.Class)", + "public abstract java.lang.Object javax.script.Invocable.invokeFunction(java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", + "public abstract java.lang.Object javax.script.Invocable.invokeMethod(java.lang.Object,java.lang.String,java.lang.Object[]) throws javax.script.ScriptException,java.lang.NoSuchMethodException", + }; + // get all declared methods Method[] declaredMethods = this.invocableClass.getDeclaredMethods(); // and transform the array into a list of method names @@ -368,6 +413,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), @@ -378,6 +424,7 @@ /** * Test for instanceof operator applied to a class javax.script.Invocable */ + @SuppressWarnings("cast") protected void testInstanceOf() { // tested object Object o = (Invocable)(new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript));