changeset 358:3c0edf5a83fc draft

Ten new tests added into ScriptContextTest.
author ptisnovs
date Thu, 15 May 2014 13:41:19 +0200
parents 5f9eba77856c
children 324c54e484c1
files ChangeLog src/org/RhinoTests/ScriptContextTest.java
diffstat 2 files changed, 173 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 15 11:45:12 2014 +0200
+++ b/ChangeLog	Thu May 15 13:41:19 2014 +0200
@@ -1,3 +1,8 @@
+2014-05-15  Pavel Tisnovsky  <ptisnovs@redhat.com>
+
+	* src/org/RhinoTests/ScriptContextTest.java:
+	Ten new tests added into ScriptContextTest.
+
 2014-05-15  Pavel Tisnovsky  <ptisnovs@redhat.com>
 
 	* src/org/RhinoTests/BaseRhinoTest.java:
--- a/src/org/RhinoTests/ScriptContextTest.java	Thu May 15 11:45:12 2014 +0200
+++ b/src/org/RhinoTests/ScriptContextTest.java	Thu May 15 13:41:19 2014 +0200
@@ -40,18 +40,185 @@
 
 package org.RhinoTests;
 
+import javax.script.ScriptContext;
+import javax.script.SimpleScriptContext;
+
 /**
  * TODO: not implemented
  * @author ptisnovs
  *
  */
-public class ScriptContextTest {
+public class ScriptContextTest extends BaseRhinoTest {
+
+    @Override
+    protected void setUp(String[] args) {
+        // this block could be empty
+        return;
+    }
+
+    @Override
+    protected void tearDown() {
+        // this block could be empty
+        return;
+    }
+
+    /**
+     * Test for toString() method.
+     */
+    protected void testToString() {
+        // tested object
+        Object object = new SimpleScriptContext();
+
+        // call the toString() method
+        String string = object.toString();
+
+        assertTrue(string != null, "toString() method returned null!");
+        assertTrue(string.startsWith("javax.script.SimpleScriptContext"), "bad toString() return value " + string);
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute1() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("name", "value", ScriptContext.ENGINE_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute2() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("name", "", ScriptContext.ENGINE_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute3() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("name", null, ScriptContext.ENGINE_SCOPE);
+        }
+        catch (Exception e) {
+            e.printStackTrace();
+            throw new AssertionError(e.getMessage());
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute4() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", \"value\", ScriptContext.ENGINE_SCOPE.) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute5() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("", "", ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute6() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute("", null, ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(\"\", null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute7() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, \"value\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute8() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute(null, "", ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
+    /**
+     * Test for method SimpleScriptContext.setAttribute().
+     */
+    protected void testSetAttribute9() {
+        // tested object
+        SimpleScriptContext object = new SimpleScriptContext();
+        try {
+            object.setAttribute(null, null, ScriptContext.ENGINE_SCOPE);
+            throw new AssertionError("ScriptContext.setAttribute(null, null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
+        }
+        catch (Exception e) {
+            // expected exception
+        }
+    }
+
     /**
      * Entry point to this test case.
      *
      * @param args parameters passed from command line
      */
     public static void main(String[] args) {
+        new ScriptContextTest().doTests(args);
     }
 
 }
+