/hg/rhino-tests: Ten new tests added into ScriptContextTest.

ptisnovs at icedtea.classpath.org ptisnovs at icedtea.classpath.org
Tue May 20 07:04:36 UTC 2014


changeset 7d92b73d875d in /hg/rhino-tests
details: http://icedtea.classpath.org/hg/rhino-tests?cmd=changeset;node=7d92b73d875d
author: ptisnovs
date: Tue May 20 09:04:26 2014 +0200

	Ten new tests added into ScriptContextTest.


diffstat:

 ChangeLog                                 |    5 +
 src/org/RhinoTests/ScriptContextTest.java |  212 +++++++++++++++++++++++++++++-
 2 files changed, 215 insertions(+), 2 deletions(-)

diffs (249 lines):

diff -r 6f5566e8e8cf -r 7d92b73d875d ChangeLog
--- a/ChangeLog	Tue May 20 08:52:43 2014 +0200
+++ b/ChangeLog	Tue May 20 09:04:26 2014 +0200
@@ -1,3 +1,8 @@
+2014-05-20  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
+	* src/org/RhinoTests/ScriptContextTest.java:
+	Ten new tests added into ScriptContextTest.
+
 2014-05-20  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
 	* src/org/RhinoTests/SimpleBindingsTest.java:
diff -r 6f5566e8e8cf -r 7d92b73d875d src/org/RhinoTests/ScriptContextTest.java
--- a/src/org/RhinoTests/ScriptContextTest.java	Tue May 20 08:52:43 2014 +0200
+++ b/src/org/RhinoTests/ScriptContextTest.java	Tue May 20 09:04:26 2014 +0200
@@ -40,16 +40,29 @@
 
 package org.RhinoTests;
 
+import java.util.HashMap;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
 import javax.script.ScriptContext;
 import javax.script.SimpleScriptContext;
 
+
+
 /**
- * TODO: not implemented
- * @author ptisnovs
+ * Basic ScriptContext test suite. Following tests checks the interface
+ * javax.script.ScriptContext.
  *
+ * @author Pavel Tisnovsky
  */
 public class ScriptContextTest extends BaseRhinoTest {
 
+    /**
+     * Many methods accepts ScriptContext.GLOBAL_SCOPE or ScriptContext.ENGINE_SCOPE
+     * as one integer parameters. Let's see how those methods works with different value.
+     */
+    private final static Integer INVALID_SCOPE = 42;
+
     @Override
     protected void setUp(String[] args) {
         // this block could be empty
@@ -347,6 +360,201 @@
     }
 
     /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute19() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("name", "value", ScriptContext.GLOBAL_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute20() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("name", "", ScriptContext.GLOBAL_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute21() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("name", null, ScriptContext.GLOBAL_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute22() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("", "value", ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", \"value\", ScriptContext.GLOBAL_SCOPE.) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute23() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("", "", ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", \"\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute24() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute("", null, ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", null, ScriptContext.GLOBAL_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute25() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute(null, "value", ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, \"value\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute26() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute(null, "", ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, \"\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute27() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+
+        // setup global scope
+        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
+        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
+
+        try {
+            object.setAttribute(null, null, ScriptContext.GLOBAL_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, null, ScriptContext.GLOBAL_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute28() {
+        // tested object
+        ScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("name", "value", INVALID_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
      * Entry point to this test case.
      *
      * @param args parameters passed from command line


More information about the distro-pkg-dev mailing list