/hg/rhino-tests: Make the test src/org/RhinoTests/InvocableClass...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Mon Oct 15 05:42:16 PDT 2012
changeset a34c578cc02b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=a34c578cc02b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Mon Oct 15 14:44:52 2012 +0200
Make the test src/org/RhinoTests/InvocableClassTest.java compatible with JDK 7.
diffstat:
ChangeLog | 5 ++
src/org/RhinoTests/InvocableClassTest.java | 63 ++++++++++++++++++++++++++---
2 files changed, 60 insertions(+), 8 deletions(-)
diffs (165 lines):
diff -r abe703a3501c -r a34c578cc02b ChangeLog
--- 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 at redhat.com>
+
+ * src/org/RhinoTests/InvocableClassTest.java:
+ Make this test compatible with JDK 7.
+
2012-10-12 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/InvocableClassTest.java:
diff -r abe703a3501c -r a34c578cc02b 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));
More information about the distro-pkg-dev
mailing list