Mercurial > hg > rhino-tests
changeset 32:e3f5a19ce034 draft
Various enhancements and corrections: make inner classes static,
encoding of external files containing script are now explicitly
specified, platform-specific line separator is used in
System.out.printf() method.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Fri, 07 Sep 2012 10:33:47 +0200 |
parents | a5384678025c |
children | d649db1c7d07 |
files | ChangeLog src/org/RhinoTests/Constants.java src/org/RhinoTests/JavaScriptsTest.java src/org/RhinoTests/ScriptEngineFactoryTest.java src/org/RhinoTests/ScriptExceptionTest.java |
diffstat | 5 files changed, 45 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Sep 06 15:39:22 2012 +0200 +++ b/ChangeLog Fri Sep 07 10:33:47 2012 +0200 @@ -1,3 +1,13 @@ +2012-09-07 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/Constants.java: + Enhancement: inner classes are static. + * src/org/RhinoTests/JavaScriptsTest.java: + * src/org/RhinoTests/ScriptExceptionTest.java: + Corrected: specified encoding of external files containing script. + * src/org/RhinoTests/ScriptEngineFactoryTest.java: + Corrected: use platform-specific line separator. + 2012-09-06 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/AbstractScriptEngineClassTest.java:
--- a/src/org/RhinoTests/Constants.java Thu Sep 06 15:39:22 2012 +0200 +++ b/src/org/RhinoTests/Constants.java Fri Sep 07 10:33:47 2012 +0200 @@ -46,12 +46,13 @@ * @author Pavel Tisnovsky */ public class Constants { + /** * Constants for known engine names or aliases for JavaScript engine. * * @author Pavel Tisnovsky */ - public class EngineNames { + public static class EngineNames { protected static final String ENGINE_NAME_JavaScript = "JavaScript"; protected static final String ENGINE_NAME_javascript = "javascript"; protected static final String ENGINE_NAME_ECMAScript = "ECMAScript"; @@ -65,7 +66,7 @@ * * @author Pavel Tisnovsky */ - public class MimeTypes { + public static class MimeTypes { protected static final String MIME_TYPE_TEXT_JAVASCRIPT = "text/javascript"; protected static final String MIME_TYPE_TEXT_ECMASCRIPT = "text/ecmascript"; protected static final String MIME_TYPE_APPLICATION_JAVASCRIPT = "application/javascript"; @@ -77,7 +78,7 @@ * * @author Pavel Tisnovsky */ - public class FileExtensions { + public static class FileExtensions { protected static final String EXTENSION_js = "js"; }
--- a/src/org/RhinoTests/JavaScriptsTest.java Thu Sep 06 15:39:22 2012 +0200 +++ b/src/org/RhinoTests/JavaScriptsTest.java Fri Sep 07 10:33:47 2012 +0200 @@ -43,6 +43,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.StringReader; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -59,6 +60,11 @@ * @author Pavel Tisnovsky */ public class JavaScriptsTest extends BaseRhinoTest { + /** + * Encoding used in JavaScript files. + */ + private static final String SCRIPT_DEFAULT_ENCODING = "UTF-8"; + ScriptEngineManager engineManager; ScriptEngine scriptEngine; @@ -338,10 +344,11 @@ * * @throws ScriptException * this exception is thrown when this test case failed. + * @throws UnsupportedEncodingException */ - protected void testRunSimpleScriptStoredInFile() throws ScriptException { + protected void testRunSimpleScriptStoredInFile() throws ScriptException, UnsupportedEncodingException { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_hello_world.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } /** @@ -353,7 +360,7 @@ */ protected void testRunEmptyScript1StoredInFile() throws Exception { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_empty_script_1.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } /** @@ -366,7 +373,7 @@ protected void testRunScriptContainingUnknownFunctionFromFile() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_unknown_function.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -384,7 +391,7 @@ protected void testRunScriptContainingError1FromFile() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_parameter.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -402,7 +409,7 @@ protected void testRunScriptContainingError2FromFile() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_command_1.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -419,7 +426,7 @@ protected void testRunSimpleScriptFromStoredInNonexistent() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/file_not_exists.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (NullPointerException e) { return; // ok, it's correct if this exception is thrown
--- a/src/org/RhinoTests/ScriptEngineFactoryTest.java Thu Sep 06 15:39:22 2012 +0200 +++ b/src/org/RhinoTests/ScriptEngineFactoryTest.java Fri Sep 07 10:33:47 2012 +0200 @@ -98,11 +98,11 @@ String languageName = factory.getLanguageName(); String languageVersion = factory.getLanguageVersion(); - System.out.printf("\tScript Engine: %s (%s)\n", engineName, engineVersion); + System.out.printf("\tScript Engine: %s (%s)%n", engineName, engineVersion); for (String name : factory.getNames()) { - System.out.printf("\tEngine Alias: %s\n", name); + System.out.printf("\tEngine Alias: %s%n", name); } - System.out.printf("\tLanguage: %s (%s)\n", languageName, languageVersion); + System.out.printf("\tLanguage: %s (%s)%n", languageName, languageVersion); } }
--- a/src/org/RhinoTests/ScriptExceptionTest.java Thu Sep 06 15:39:22 2012 +0200 +++ b/src/org/RhinoTests/ScriptExceptionTest.java Fri Sep 07 10:33:47 2012 +0200 @@ -55,6 +55,11 @@ * @author Pavel Tisnovsky */ public class ScriptExceptionTest extends BaseRhinoTest { + /** + * Encoding used in JavaScript files. + */ + private static final String SCRIPT_DEFAULT_ENCODING = "UTF-8"; + ScriptEngineManager engineManager; ScriptEngine scriptEngine; Invocable invocableEngine; @@ -244,7 +249,7 @@ protected void testBasicScriptExceptionTestErrorInExternalScript1() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_unknown_function.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -263,7 +268,7 @@ protected void testBasicScriptExceptionTestErrorInExternalScript2() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_parameter.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -282,7 +287,7 @@ protected void testBasicScriptExceptionTestErrorInExternalScript3() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_command_1.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -301,7 +306,7 @@ protected void testBasicScriptExceptionTestErrorInExternalScript4() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_parameter.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { return; // ok, it's correct if this exception is thrown @@ -362,7 +367,7 @@ protected void testScriptExceptionTestLineNumber3() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_unknown_function.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { assertEquals(1, e.getLineNumber(), "wrong line number returned " + e.getLineNumber()); @@ -382,7 +387,7 @@ protected void testScriptExceptionTestLineNumber4() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_parameter.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { assertEquals(1, e.getLineNumber(), "wrong line number returned " + e.getLineNumber()); @@ -402,7 +407,7 @@ protected void testScriptExceptionTestLineNumber5() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_command_1.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { assertEquals(1, e.getLineNumber(), "wrong line number returned " + e.getLineNumber()); @@ -422,7 +427,7 @@ protected void testScriptExceptionTestLineNumber6() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_command_2.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { assertEquals(3, e.getLineNumber(), "wrong line number returned " + e.getLineNumber()); @@ -442,7 +447,7 @@ protected void testScriptExceptionTestLineNumber7() throws Exception { try { InputStream inputStream = this.getClass().getResourceAsStream("scripts/test_invalid_command_3.js"); - this.scriptEngine.eval(new InputStreamReader(inputStream)); + this.scriptEngine.eval(new InputStreamReader(inputStream, SCRIPT_DEFAULT_ENCODING)); } catch (ScriptException e) { assertEquals(3, e.getLineNumber(), "wrong line number returned " + e.getLineNumber());