/hg/rhino-tests: * src/org/RhinoTests/CompilableTest.java:
ptisnovs at icedtea.classpath.org
ptisnovs at icedtea.classpath.org
Thu Sep 20 03:02:56 PDT 2012
changeset c07fce915c2b in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=c07fce915c2b
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Thu Sep 20 12:05:21 2012 +0200
* src/org/RhinoTests/CompilableTest.java:
Added two new tests.
* src/org/RhinoTests/CompilableClassTest.java:
Removed unnecessarry explicit casting.
* src/org/RhinoTests/CompiledScriptTest.java:
Fixed typo.
diffstat:
ChangeLog | 9 ++
src/org/RhinoTests/CompilableClassTest.java | 3 +-
src/org/RhinoTests/CompilableTest.java | 110 +++++++++++++++++++++++++++-
src/org/RhinoTests/CompiledScriptTest.java | 1 +
4 files changed, 118 insertions(+), 5 deletions(-)
diffs (176 lines):
diff -r be1b5714e3f0 -r c07fce915c2b ChangeLog
--- a/ChangeLog Wed Sep 19 10:18:40 2012 +0200
+++ b/ChangeLog Thu Sep 20 12:05:21 2012 +0200
@@ -1,3 +1,12 @@
+2012-09-20 Pavel Tisnovsky <ptisnovs at redhat.com>
+
+ * src/org/RhinoTests/CompilableTest.java:
+ Added two new tests.
+ * src/org/RhinoTests/CompilableClassTest.java:
+ Removed unnecessarry explicit casting.
+ * src/org/RhinoTests/CompiledScriptTest.java:
+ Fixed typo.
+
2012-09-19 Pavel Tisnovsky <ptisnovs at redhat.com>
* src/org/RhinoTests/CompilableClassTest.java:
diff -r be1b5714e3f0 -r c07fce915c2b src/org/RhinoTests/CompilableClassTest.java
--- a/src/org/RhinoTests/CompilableClassTest.java Wed Sep 19 10:18:40 2012 +0200
+++ b/src/org/RhinoTests/CompilableClassTest.java Thu Sep 20 12:05:21 2012 +0200
@@ -51,7 +51,6 @@
import javax.script.Compilable;
import javax.script.ScriptEngineManager;
-import javax.script.ScriptEngine;
@@ -92,7 +91,7 @@
* Test for method javax.script.Compilable.getClass().isInstance()
*/
protected void testIsInstance() {
- assertTrue(this.compilableClass.isInstance((Compilable)(new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript))),
+ assertTrue(this.compilableClass.isInstance((new ScriptEngineManager().getEngineByName(Constants.EngineNames.ENGINE_NAME_JavaScript))),
"Method Compilable.getClass().isInstance() returns wrong value");
}
diff -r be1b5714e3f0 -r c07fce915c2b src/org/RhinoTests/CompilableTest.java
--- a/src/org/RhinoTests/CompilableTest.java Wed Sep 19 10:18:40 2012 +0200
+++ b/src/org/RhinoTests/CompilableTest.java Thu Sep 20 12:05:21 2012 +0200
@@ -40,18 +40,122 @@
package org.RhinoTests;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+
/**
- * TODO: not implemented
+ * This test case check the behaviour of CompiledScript abstract class and it's
+ * descendents.
+ *
* @author Pavel Tisnovsky
- *
+ *
*/
-public class CompilableTest {
+public class CompilableTest extends BaseRhinoTest {
+
+ /**
+ * Empty, but still valid script.
+ */
+ private static final String EMPTY_SCRIPT = "";
+
+ /**
+ * Instance of ScriptEngineManager which is used by all tests in this test
+ * case.
+ */
+ ScriptEngineManager engineManager;
+
+ /**
+ * Instance of ScriptEngine which is used by all tests in this test case.
+ */
+ ScriptEngine scriptEngine;
+
+ @Override
+ protected void setUp(String[] args) {
+ // setup attribute used by tests
+ this.engineManager = new ScriptEngineManager();
+ this.scriptEngine = this.engineManager.getEngineByName("JavaScript");
+ }
+
+ @Override
+ protected void tearDown() {
+ // this block could be empty
+ return;
+ }
+
+ /**
+ * Helper method which tries to retrieve an instance of class which
+ * implements CompiledScript interface for a given script.
+ *
+ * @param scriptText
+ * script source code
+ * @return instance of CompiledScript class
+ * @throws AssertionError
+ * when CompilingEngine cannot be retrieved
+ * @throws ScriptException
+ * thrown when script cannot be compiled
+ */
+ private CompiledScript getCompiledScript(String scriptText) throws AssertionError, ScriptException {
+ // check if retyping could be done
+ assertTrue(this.scriptEngine instanceof Compilable, "ScriptEngine does not implement Compilable");
+ // scriptEngine should be also retyped to Compilable, at least in case of JavaScript.
+ Compilable compilingEngine = (Compilable) this.scriptEngine;
+ // should not happen, but...
+ assertNotNull(compilingEngine, "cannot get compiling engine");
+ // try to compile given script
+ return compileScript(scriptText, compilingEngine);
+ }
+
+ /**
+ * Helper method which tries to compile given JavaScript.
+ *
+ * @param scriptText script source code
+ * @param compilingEngine instance of class which implements Compilable interface
+ * @return compiled script
+ * @throws ScriptException
+ * @throws AssertionError
+ */
+ private CompiledScript compileScript(String scriptText, Compilable compilingEngine) throws ScriptException, AssertionError {
+ CompiledScript script = compilingEngine.compile(scriptText);
+ assertNotNull(script, "cannot compile script");
+ return script;
+ }
+
+ /**
+ * Test if it is possible to compile script from a string.
+ *
+ * @throws ScriptException
+ * this exception is thrown when this test case failed.
+ */
+ protected void testCompileScriptStoredInString() throws ScriptException {
+ Compilable compilingEngine = (Compilable)this.scriptEngine;
+ assertNotNull(compilingEngine, "cannot get compiling engine");
+ if (compilingEngine != null) {
+ CompiledScript script = compilingEngine.compile(EMPTY_SCRIPT);
+ assertNotNull(script, "cannot compile script");
+ }
+ }
+
+ /**
+ * Test if it is possible to compile and then run script from a string.
+ *
+ * @throws ScriptException
+ * this exception is thrown when this test case failed.
+ */
+ protected void testCompileAndRunSimpleScriptStoredInString() throws ScriptException {
+ CompiledScript script = getCompiledScript(EMPTY_SCRIPT);
+ Object result = script.eval();
+ assertNull(result, "result should be null");
+ }
+
/**
* Entry point to this test case.
*
* @param args parameters passed from command line
*/
public static void main(String[] args) {
+ new CompilableTest().doTests(args);
}
}
diff -r be1b5714e3f0 -r c07fce915c2b src/org/RhinoTests/CompiledScriptTest.java
--- a/src/org/RhinoTests/CompiledScriptTest.java Wed Sep 19 10:18:40 2012 +0200
+++ b/src/org/RhinoTests/CompiledScriptTest.java Thu Sep 20 12:05:21 2012 +0200
@@ -67,6 +67,7 @@
@Override
protected void setUp(String[] args) {
+ // setup attribute used by tests
this.engineManager = new ScriptEngineManager();
this.scriptEngine = this.engineManager.getEngineByName("JavaScript");
}
More information about the distro-pkg-dev
mailing list