/hg/rhino-tests: Make this test compatible with JDK 7 and added ...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Thu Oct 11 02:59:07 PDT 2012
changeset dc091793be64 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=dc091793be64
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Oct 11 12:01:51 2012 +0200
Make this test compatible with JDK 7 and added new case: ssrc/org/RhinoTests/CompiledScriptClassTest.java.
diffstat:
ChangeLog | 5 +
src/org/RhinoTests/CompiledScriptClassTest.java | 101 +++++++++++++++++++----
2 files changed, 85 insertions(+), 21 deletions(-)
diffs (185 lines):
diff -r 6d02300b36fa -r dc091793be64 ChangeLog
--- a/ChangeLog Wed Oct 10 12:45:08 2012 +0200
+++ b/ChangeLog Thu Oct 11 12:01:51 2012 +0200
@@ -1,3 +1,8 @@
+2012-10-11 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/CompiledScriptClassTest.java:
+ Make this test compatible with JDK 7 and added new cases.
+
2012-10-10 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/BindingsClassTest.java:
diff -r 6d02300b36fa -r dc091793be64 src/org/RhinoTests/CompiledScriptClassTest.java
--- a/src/org/RhinoTests/CompiledScriptClassTest.java Wed Oct 10 12:45:08 2012 +0200
+++ b/src/org/RhinoTests/CompiledScriptClassTest.java Thu Oct 11 12:01:51 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;
@@ -144,7 +146,7 @@
/**
* Test for method javax.script.CompiledScript.getClass().isInstance()
*/
- protected void testIsInstance() throws ScriptException {
+ protected void testIsInstance() throws javax.script.ScriptException {
assertTrue(this.compiledScriptClass.isInstance(getCompiledScript("6*7")),
"Method CompiledScript.getClass().isInstance() returns wrong value");
}
@@ -325,32 +327,62 @@
* Test for method javax.script.CompiledScript.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.CompiledScript()", "javax.script.CompiledScript");
+
+ testedConstructors_jdk7.put("public javax.script.CompiledScript()", "javax.script.CompiledScript");
+
+ // get the right map containing constructor signatures
+ testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+ // get all constructors for this class
Constructor<?>[] constructors = this.compiledScriptClass.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.CompiledScript",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.CompiledScript()",
- "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.CompiledScript.getClass().getDeclaredConstructors()
*/
protected void testGetDeclaredConstructors() {
- Constructor<?>[] constructors = this.compiledScriptClass.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.CompiledScript",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.CompiledScript()",
- "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.CompiledScript()", "javax.script.CompiledScript");
+
+ testedConstructors_jdk7.put("public javax.script.CompiledScript()", "javax.script.CompiledScript");
+
+ // get the right map containing constructor signatures
+ testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+ // get all declared constructors for this class
+ Constructor<?>[] declaredConstructors = this.compiledScriptClass.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);
+ }
}
/**
@@ -400,7 +432,7 @@
*/
protected void testGetMethods() {
// following methods should be inherited
- final String[] methodsThatShouldExists = {
+ final String[] methodsThatShouldExists_jdk6 = {
"public abstract java.lang.Object javax.script.CompiledScript.eval(javax.script.ScriptContext) throws javax.script.ScriptException",
"public abstract javax.script.ScriptEngine javax.script.CompiledScript.getEngine()",
"public boolean java.lang.Object.equals(java.lang.Object)",
@@ -415,6 +447,23 @@
"public java.lang.String java.lang.Object.toString()",
"public native int java.lang.Object.hashCode()",
};
+
+ final String[] methodsThatShouldExists_jdk7 = {
+ "public abstract java.lang.Object javax.script.CompiledScript.eval(javax.script.ScriptContext) throws javax.script.ScriptException",
+ "public abstract javax.script.ScriptEngine javax.script.CompiledScript.getEngine()",
+ "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 java.lang.Object javax.script.CompiledScript.eval() throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.CompiledScript.eval(javax.script.Bindings) throws javax.script.ScriptException",
+ "public java.lang.String java.lang.Object.toString()",
+ "public native int java.lang.Object.hashCode()",
+ };
+
// get all inherited methods
Method[] methods = this.compiledScriptClass.getMethods();
// and transform the array into a list of method names
@@ -422,6 +471,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),
@@ -434,12 +484,20 @@
*/
protected void testGetDeclaredMethods() {
// following methods should be declared
- final String[] declaredMethodsThatShouldExists = {
+ final String[] declaredMethodsThatShouldExists_jdk6 = {
"public abstract java.lang.Object javax.script.CompiledScript.eval(javax.script.ScriptContext) throws javax.script.ScriptException",
"public abstract javax.script.ScriptEngine javax.script.CompiledScript.getEngine()",
"public java.lang.Object javax.script.CompiledScript.eval() throws javax.script.ScriptException",
"public java.lang.Object javax.script.CompiledScript.eval(javax.script.Bindings) throws javax.script.ScriptException",
};
+
+ final String[] declaredMethodsThatShouldExists_jdk7 = {
+ "public abstract java.lang.Object javax.script.CompiledScript.eval(javax.script.ScriptContext) throws javax.script.ScriptException",
+ "public abstract javax.script.ScriptEngine javax.script.CompiledScript.getEngine()",
+ "public java.lang.Object javax.script.CompiledScript.eval() throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.CompiledScript.eval(javax.script.Bindings) throws javax.script.ScriptException",
+ };
+
// get all declared methods
Method[] declaredMethods = this.compiledScriptClass.getDeclaredMethods();
// and transform the array into a list of method names
@@ -447,6 +505,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),
More information about the distro-pkg-dev
mailing list