Mercurial > hg > rhino-tests
changeset 63:649ff1c652d1 draft
Added eight new tests to src/org/RhinoTests/BindingsTest.java.
author | Pavel Tisnovsky <ptisnovs@redhat.com> |
---|---|
date | Fri, 16 Nov 2012 11:46:08 +0100 |
parents | 610558995315 |
children | bba804edaeab |
files | ChangeLog src/org/RhinoTests/BindingsTest.java |
diffstat | 2 files changed, 92 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Nov 15 10:22:11 2012 +0100 +++ b/ChangeLog Fri Nov 16 11:46:08 2012 +0100 @@ -1,3 +1,8 @@ +2012-11-16 Pavel Tisnovsky <ptisnovs@redhat.com> + + * src/org/RhinoTests/BindingsTest.java: + Added eight new tests. + 2012-11-15 Pavel Tisnovsky <ptisnovs@redhat.com> * src/org/RhinoTests/ScriptEngineFactoryClassTest.java:
--- a/src/org/RhinoTests/BindingsTest.java Thu Nov 15 10:22:11 2012 +0100 +++ b/src/org/RhinoTests/BindingsTest.java Fri Nov 16 11:46:08 2012 +0100 @@ -1,7 +1,7 @@ /* Rhino test framework - Copyright (C) 2011 Red Hat + Copyright (C) 2011, 2012 Red Hat This file is part of IcedTea. @@ -40,18 +40,102 @@ package org.RhinoTests; +import java.util.HashMap; +import java.util.TreeMap; + +import javax.script.SimpleBindings; +import javax.script.Bindings; + /** - * TODO: not implemented * @author Pavel Tisnovsky * */ -public class BindingsTest { +public class BindingsTest extends BaseRhinoTest { + + @Override + protected void setUp(String[] args) { + // this block could be empty + return; + } + + @Override + protected void tearDown() { + // this block could be empty + return; + } + + protected void testConstructor1() { + Bindings bindings = new SimpleBindings(); + assertNotNull(bindings, "new SimpleBindings() failed"); + assertTrue(bindings.isEmpty(), "bindings should be empty"); + assertTrue(bindings.size() == 0, "bindings should be empty"); + } + + protected void testConstructor2() { + Bindings bindings = new SimpleBindings(new HashMap()); + assertNotNull(bindings, "new SimpleBindings() failed"); + assertTrue(bindings.isEmpty(), "bindings should be empty"); + assertTrue(bindings.size() == 0, "bindings should be empty"); + } + + protected void testConstructor3() { + Bindings bindings = new SimpleBindings(new TreeMap()); + assertNotNull(bindings, "new SimpleBindings() failed"); + assertTrue(bindings.isEmpty(), "bindings should be empty"); + assertTrue(bindings.size() == 0, "bindings should be empty"); + } + + protected void testContainsKey1() { + Bindings bindings = new SimpleBindings(); + assertFalse(bindings.containsKey("key"), "Bingings.containsKey() failed"); + } + + protected void testContainsKey2() { + Bindings bindings = new SimpleBindings(); + bindings.put("key", "value"); + assertTrue(bindings.containsKey("key"), "Bingings.containsKey() failed"); + } + + protected void testContainsKeyNegative1() throws Exception { + Bindings bindings = new SimpleBindings(); + try { + bindings.containsKey(null); + } + catch (NullPointerException e) { + return; + } + throw new Exception("NPE did not thrown as expected"); + } + + protected void testContainsKeyNegative2() throws Exception { + Bindings bindings = new SimpleBindings(); + try { + bindings.containsKey(""); + } + catch (IllegalArgumentException e) { + return; + } + throw new Exception("IllegalArgumentException did not thrown as expected"); + } + + protected void testContainsKeyNegative3() throws Exception { + Bindings bindings = new SimpleBindings(); + try { + bindings.containsKey(new Integer(42)); + } + catch (ClassCastException e) { + return; + } + throw new Exception("ClassCastException did not thrown as expected"); + } + /** * Entry point to this test case. * * @param args parameters passed from command line */ public static void main(String[] args) { + new BindingsTest().doTests(args); } }