/hg/rhino-tests: Various enhancements and corrections: make inne...

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Fri Sep 7 01:31:14 PDT 2012


changeset e3f5a19ce034 in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=e3f5a19ce034
author: Pavel Tisnovsky <ptisnovs at redhat.com>
date: Fri Sep 07 10:33:47 2012 +0200

	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.


diffstat:

 ChangeLog                                       |  10 ++++++++++
 src/org/RhinoTests/Constants.java               |   7 ++++---
 src/org/RhinoTests/JavaScriptsTest.java         |  21 ++++++++++++++-------
 src/org/RhinoTests/ScriptEngineFactoryTest.java |   6 +++---
 src/org/RhinoTests/ScriptExceptionTest.java     |  23 ++++++++++++++---------
 5 files changed, 45 insertions(+), 22 deletions(-)

diffs (249 lines):

diff -r a5384678025c -r e3f5a19ce034 ChangeLog
--- 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 at 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 at redhat.com>
 
 	* src/org/RhinoTests/AbstractScriptEngineClassTest.java:
diff -r a5384678025c -r e3f5a19ce034 src/org/RhinoTests/Constants.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";
     }
 
diff -r a5384678025c -r e3f5a19ce034 src/org/RhinoTests/JavaScriptsTest.java
--- 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
diff -r a5384678025c -r e3f5a19ce034 src/org/RhinoTests/ScriptEngineFactoryTest.java
--- 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);
         }
     }
 
diff -r a5384678025c -r e3f5a19ce034 src/org/RhinoTests/ScriptExceptionTest.java
--- 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());



More information about the distro-pkg-dev mailing list