/hg/rhino-tests: Make the test AbstractScriptEngineClassTest com...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Wed Sep 26 02:23:41 PDT 2012
changeset a3b0d341d76b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=a3b0d341d76b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Sep 26 11:26:17 2012 +0200
Make the test AbstractScriptEngineClassTest compatible with JDK 7.
diffstat:
ChangeLog | 5 +
src/org/RhinoTests/AbstractScriptEngineClassTest.java | 132 +++++++++++++----
2 files changed, 105 insertions(+), 32 deletions(-)
diffs (211 lines):
diff -r 466d720bca82 -r a3b0d341d76b ChangeLog
--- a/ChangeLog Tue Sep 25 10:54:08 2012 +0200
+++ b/ChangeLog Wed Sep 26 11:26:17 2012 +0200
@@ -1,3 +1,8 @@
+2012-09-26 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/AbstractScriptEngineClassTest.java:
+ Make this test compatible with JDK 7.
+
2012-09-25 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/SimpleBindingsClassTest.java:
diff -r 466d720bca82 -r a3b0d341d76b src/org/RhinoTests/AbstractScriptEngineClassTest.java
--- a/src/org/RhinoTests/AbstractScriptEngineClassTest.java Tue Sep 25 10:54:08 2012 +0200
+++ b/src/org/RhinoTests/AbstractScriptEngineClassTest.java Wed Sep 26 11:26:17 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;
@@ -271,44 +273,66 @@
* Test for method javax.script.AbstractScriptEngine.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.AbstractScriptEngine()", "javax.script.AbstractScriptEngine");
+ testedConstructors_jdk6.put("public javax.script.AbstractScriptEngine(javax.script.Bindings)", "javax.script.AbstractScriptEngine");
+
+ testedConstructors_jdk7.put("public javax.script.AbstractScriptEngine()", "javax.script.AbstractScriptEngine");
+ testedConstructors_jdk7.put("public javax.script.AbstractScriptEngine(javax.script.Bindings)", "javax.script.AbstractScriptEngine");
+
+ // get the right map containing constructor signatures
+ testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+ // get all constructors for this class
Constructor<?>[] constructors = this.abstractScriptEngineClass.getConstructors();
+
+ // basic check for a number of constructors
assertEquals(constructors.length, 2, "only 2 constructors should be set");
- String constructorName;
- String constructorString;
- constructorName = constructors[0].getName();
- constructorString = constructors[0].toString();
- assertEquals(constructorName, "javax.script.AbstractScriptEngine",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.AbstractScriptEngine()",
- "wrong constructor.toString() " + constructorName);
- constructorName = constructors[1].getName();
- constructorString = constructors[1].toString();
- assertEquals(constructorName, "javax.script.AbstractScriptEngine",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.AbstractScriptEngine(javax.script.Bindings)",
- "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.AbstractScriptEngine.getClass().getDeclaredConstructors()
*/
protected void testGetDeclaredConstructors() {
- Constructor<?>[] constructors = this.abstractScriptEngineClass.getDeclaredConstructors();
- assertEquals(constructors.length, 2, "only 2 constructors should be set");
- String constructorName;
- String constructorString;
- constructorName = constructors[0].getName();
- constructorString = constructors[0].toString();
- assertEquals(constructorName, "javax.script.AbstractScriptEngine",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.AbstractScriptEngine()",
- "wrong constructor.toString() " + constructorName);
- constructorName = constructors[1].getName();
- constructorString = constructors[1].toString();
- assertEquals(constructorName, "javax.script.AbstractScriptEngine",
- "wrong constructor name " + constructorName);
- assertEquals(constructorString, "public javax.script.AbstractScriptEngine(javax.script.Bindings)",
- "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.AbstractScriptEngine()", "javax.script.AbstractScriptEngine");
+ testedConstructors_jdk6.put("public javax.script.AbstractScriptEngine(javax.script.Bindings)", "javax.script.AbstractScriptEngine");
+
+ testedConstructors_jdk7.put("public javax.script.AbstractScriptEngine()", "javax.script.AbstractScriptEngine");
+ testedConstructors_jdk7.put("public javax.script.AbstractScriptEngine(javax.script.Bindings)", "javax.script.AbstractScriptEngine");
+
+ // get the right map containing constructor signatures
+ testedConstructors = getJavaVersion() < 7 ? testedConstructors_jdk6 : testedConstructors_jdk7;
+
+ // get all declared constructors for this class
+ Constructor<?>[] declaredConstructors = this.abstractScriptEngineClass.getDeclaredConstructors();
+
+ // basic check for a number of declared constructors
+ assertEquals(declaredConstructors.length, 2, "only 2 constructors 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);
+ }
}
/**
@@ -366,7 +390,7 @@
*/
protected void testGetMethods() {
// following methods should be inherited
- final String[] methodsThatShouldExists = {
+ final String[] methodsThatShouldExists_jdk6 = {
"public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
"public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.ScriptContext) throws javax.script.ScriptException",
"public abstract javax.script.Bindings javax.script.ScriptEngine.createBindings()",
@@ -391,6 +415,33 @@
"public void javax.script.AbstractScriptEngine.setBindings(javax.script.Bindings,int)",
"public void javax.script.AbstractScriptEngine.setContext(javax.script.ScriptContext)",
};
+
+ final String[] methodsThatShouldExists_jdk7 = {
+ "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.io.Reader,javax.script.ScriptContext) throws javax.script.ScriptException",
+ "public abstract java.lang.Object javax.script.ScriptEngine.eval(java.lang.String,javax.script.ScriptContext) throws javax.script.ScriptException",
+ "public abstract javax.script.Bindings javax.script.ScriptEngine.createBindings()",
+ "public abstract javax.script.ScriptEngineFactory javax.script.ScriptEngine.getFactory()",
+ "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.AbstractScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.lang.String) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.lang.String,javax.script.Bindings) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.get(java.lang.String)",
+ "public java.lang.String java.lang.Object.toString()",
+ "public javax.script.Bindings javax.script.AbstractScriptEngine.getBindings(int)",
+ "public javax.script.ScriptContext javax.script.AbstractScriptEngine.getContext()",
+ "public native int java.lang.Object.hashCode()",
+ "public void javax.script.AbstractScriptEngine.put(java.lang.String,java.lang.Object)",
+ "public void javax.script.AbstractScriptEngine.setBindings(javax.script.Bindings,int)",
+ "public void javax.script.AbstractScriptEngine.setContext(javax.script.ScriptContext)",
+ };
+
// get all inherited methods
Method[] methods = this.abstractScriptEngineClass.getMethods();
// and transform the array into a list of method names
@@ -398,6 +449,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),
@@ -410,7 +462,7 @@
*/
protected void testGetDeclaredMethods() {
// following methods should be declared
- final String[] declaredMethodsThatShouldExists = {
+ final String[] declaredMethodsThatShouldExists_jdk6 = {
"protected javax.script.ScriptContext javax.script.AbstractScriptEngine.getScriptContext(javax.script.Bindings)",
"public java.lang.Object javax.script.AbstractScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
"public java.lang.Object javax.script.AbstractScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
@@ -423,6 +475,21 @@
"public void javax.script.AbstractScriptEngine.setBindings(javax.script.Bindings,int)",
"public void javax.script.AbstractScriptEngine.setContext(javax.script.ScriptContext)",
};
+
+ final String[] declaredMethodsThatShouldExists_jdk7 = {
+ "protected javax.script.ScriptContext javax.script.AbstractScriptEngine.getScriptContext(javax.script.Bindings)",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.io.Reader) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.io.Reader,javax.script.Bindings) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.lang.String) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.eval(java.lang.String,javax.script.Bindings) throws javax.script.ScriptException",
+ "public java.lang.Object javax.script.AbstractScriptEngine.get(java.lang.String)",
+ "public javax.script.Bindings javax.script.AbstractScriptEngine.getBindings(int)",
+ "public javax.script.ScriptContext javax.script.AbstractScriptEngine.getContext()",
+ "public void javax.script.AbstractScriptEngine.put(java.lang.String,java.lang.Object)",
+ "public void javax.script.AbstractScriptEngine.setBindings(javax.script.Bindings,int)",
+ "public void javax.script.AbstractScriptEngine.setContext(javax.script.ScriptContext)",
+ };
+
// get all declared methods
Method[] declaredMethods = this.abstractScriptEngineClass.getDeclaredMethods();
// and transform the array into a list of method names
@@ -430,6 +497,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