changeset 364:7d92b73d875d draft

Ten new tests added into ScriptContextTest.
author ptisnovs
date Tue, 20 May 2014 09:04:26 +0200
parents 6f5566e8e8cf
children 67c8a396f43f
files ChangeLog src/org/RhinoTests/ScriptContextTest.java
diffstat 2 files changed, 215 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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@redhat.com>
+
+	* src/org/RhinoTests/ScriptContextTest.java:
+	Ten new tests added into ScriptContextTest.
+
 2014-05-20  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/SimpleBindingsTest.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