# HG changeset patch # User ptisnovs # Date 1400154079 -7200 # Node ID 3c0edf5a83fc969acbb9b6eccdcc240e1ca713cc # Parent 5f9eba77856c2b062e05f4bf5337dc20ea60b028 Ten new tests added into ScriptContextTest. diff -r 5f9eba77856c -r 3c0edf5a83fc ChangeLog --- 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 + + * src/org/RhinoTests/ScriptContextTest.java: + Ten new tests added into ScriptContextTest. + 2014-05-15 Pavel Tisnovsky * src/org/RhinoTests/BaseRhinoTest.java: diff -r 5f9eba77856c -r 3c0edf5a83fc src/org/RhinoTests/ScriptContextTest.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); } } +