/hg/rhino-tests: Added check for JVM version to the BaseRhinoTes...
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Wed Aug 1 02:27:01 PDT 2012
changeset 77d7df3f99f8 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=77d7df3f99f8
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Wed Aug 01 11:29:33 2012 +0200
Added check for JVM version to the BaseRhinoTest class.
Fixed some tests which were based on older Rhino API used
in JDK6.
diffstat:
ChangeLog | 9 +++++++
src/org/RhinoTests/BaseRhinoTest.java | 12 ++++++++++
src/org/RhinoTests/CompiledScriptTest.java | 15 +++++++++---
src/org/RhinoTests/JavaScriptsTest.java | 35 +++++++++++++++++++++--------
4 files changed, 57 insertions(+), 14 deletions(-)
diffs (145 lines):
diff -r 50619c42d67c -r 77d7df3f99f8 ChangeLog
--- a/ChangeLog Mon Jul 30 15:33:41 2012 +0200
+++ b/ChangeLog Wed Aug 01 11:29:33 2012 +0200
@@ -1,3 +1,12 @@
+2012-08-01 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/BaseRhinoTest.java:
+ * src/org/RhinoTests/CompiledScriptTest.java:
+ * src/org/RhinoTests/JavaScriptsTest.java:
+ Added check for JVM version to the BaseRhinoTest class.
+ Fixed some tests which were based on older Rhino API used
+ in JDK6.
+
2012-07-30 Pavel Tisnovsky <ptisnovs at redhat.com>
* BUGS:
diff -r 50619c42d67c -r 77d7df3f99f8 src/org/RhinoTests/BaseRhinoTest.java
--- a/src/org/RhinoTests/BaseRhinoTest.java Mon Jul 30 15:33:41 2012 +0200
+++ b/src/org/RhinoTests/BaseRhinoTest.java Wed Aug 01 11:29:33 2012 +0200
@@ -472,4 +472,16 @@
protected static void assertType(Object object, Class<?> clazz, String message) throws AssertionError {
assertTrue(object.getClass().equals(clazz), message);
}
+
+ /**
+ * Returns version of Java. The input could have the following form: "1.7.0_06"
+ * and we are interested only in "7" in this case.
+ *
+ * @return Java version
+ */
+ protected int getJavaVersion() {
+ String javaVersionStr = System.getProperty("java.version");
+ String[] parts = javaVersionStr.split("\\.");
+ return Integer.parseInt(parts[1]);
+ }
}
diff -r 50619c42d67c -r 77d7df3f99f8 src/org/RhinoTests/CompiledScriptTest.java
--- a/src/org/RhinoTests/CompiledScriptTest.java Mon Jul 30 15:33:41 2012 +0200
+++ b/src/org/RhinoTests/CompiledScriptTest.java Wed Aug 01 11:29:33 2012 +0200
@@ -146,14 +146,21 @@
* @throws ScriptException
* this exception is thrown when this test case failed.
*/
- protected void testEvalIntegerExpression() throws ScriptException {
+ protected void testEvalNumericExpression() throws ScriptException {
CompiledScript script = getCompiledScript("1+2*3");
Object result = script.eval();
assertNotNull(result, "result should not be null");
assertTrue(result instanceof Number, "result is not an instance of Number");
- assertTrue(result instanceof Integer, "result is not an instance of Integer");
- int integerResult = ((Integer) result).intValue();
- assertEquals(integerResult, 7, "wrong result " + integerResult);
+ if (getJavaVersion() >= 7) {
+ assertTrue(result instanceof Double, "result is not an instance of Double");
+ double doubleResult = ((Double) result).doubleValue();
+ assertEquals(doubleResult, 7, "wrong result " + doubleResult);
+ }
+ else {
+ assertTrue(result instanceof Integer, "result is not an instance of Integer");
+ int integerResult = ((Integer) result).intValue();
+ assertEquals(integerResult, 7, "wrong result " + integerResult);
+ }
}
/**
diff -r 50619c42d67c -r 77d7df3f99f8 src/org/RhinoTests/JavaScriptsTest.java
--- a/src/org/RhinoTests/JavaScriptsTest.java Mon Jul 30 15:33:41 2012 +0200
+++ b/src/org/RhinoTests/JavaScriptsTest.java Wed Aug 01 11:29:33 2012 +0200
@@ -494,7 +494,9 @@
*/
protected void testRunSimpleScriptReturnTypeInteger1() throws Exception {
Object result = this.scriptEngine.eval("42;");
- assertType(result, java.lang.Integer.class, result.getClass().getName() + " is not expected class");
+ // expected class could be either Integer or Double due to changes in Rhino itself
+ Class<?> expectedClass = getJavaVersion() >= 7 ? java.lang.Double.class : java.lang.Integer.class;
+ assertType(result, expectedClass, result.getClass().getName() + " is not expected class");
}
/**
@@ -504,7 +506,9 @@
*/
protected void testRunSimpleScriptReturnTypeInteger2() throws Exception {
Object result = this.scriptEngine.eval("((42));");
- assertType(result, java.lang.Integer.class, result.getClass().getName() + " is not expected class");
+ // expected class could be either Integer or Double due to changes in Rhino itself
+ Class<?> expectedClass = getJavaVersion() >= 7 ? java.lang.Double.class : java.lang.Integer.class;
+ assertType(result, expectedClass, result.getClass().getName() + " is not expected class");
}
/**
@@ -514,7 +518,9 @@
*/
protected void testRunSimpleScriptReturnTypeInteger3() throws Exception {
Object result = this.scriptEngine.eval("1+2;");
- assertType(result, java.lang.Integer.class, result.getClass().getName() + " is not expected class");
+ // expected class could be either Integer or Double due to changes in Rhino itself
+ Class<?> expectedClass = getJavaVersion() >= 7 ? java.lang.Double.class : java.lang.Integer.class;
+ assertType(result, expectedClass, result.getClass().getName() + " is not expected class");
}
/**
@@ -602,9 +608,17 @@
*
* @throws Exception this exception is thrown when this test case failed.
*/
- protected void testRunSimpleScriptWhichReturnsInteger() throws Exception {
- Integer result = (Integer)this.scriptEngine.eval("1+2;");
- assertTrue(result == 3, "script returns incorrect value " + result);
+ @SuppressWarnings("boxing")
+ protected void testRunSimpleScriptWhichReturnsNumber() throws Exception {
+ Object result = this.scriptEngine.eval("1+2;");
+ if (getJavaVersion() >= 7) {
+ Double doubleResult = (Double)result;
+ assertTrue(doubleResult == 3, "script returns incorrect value " + result);
+ }
+ else {
+ Integer intResult = (Integer)result;
+ assertTrue(intResult == 3, "script returns incorrect value " + result);
+ }
}
/**
@@ -612,7 +626,8 @@
*
* @throws Exception this exception is thrown when this test case failed.
*/
- protected void testRunSimpleScriptWhichReturnsDouble() throws Exception {
+ @SuppressWarnings("boxing")
+ protected void testRunSimpleScriptWhichReturnsDouble() throws Exception {
Double result = (Double)this.scriptEngine.eval("1.2+3.4;");
assertTrue(result == 4.6, "script returns incorrect value " + result);
}
@@ -682,9 +697,9 @@
"valuesKey.add(42);" +
"println('\tNew array size:' + valuesKey.size());";
List<Double> values = new ArrayList<Double>();//Arrays.asList(new String[]{"1", "2", "3"});;
- values.add(1.);
- values.add(2.);
- values.add(3.);
+ values.add(Double.valueOf(1.));
+ values.add(Double.valueOf(2.));
+ values.add(Double.valueOf(3.));
this.scriptEngine.put("valuesKey", values);
this.scriptEngine.eval(script);
for (Double value : values) {
More information about the distro-pkg-dev
mailing list