# HG changeset patch # User ptisnovs # Date 1400569466 -7200 # Node ID 7d92b73d875d61592fb305364bfc5fee79184a95 # Parent 6f5566e8e8cf653151dc4319ea09d581b173c641 Ten new tests added into ScriptContextTest. 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 + + * src/org/RhinoTests/ScriptContextTest.java: + Ten new tests added into ScriptContextTest. + 2014-05-20 Pavel Tisnovsky * 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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