Mercurial > hg > rhino-tests
view src/org/RhinoTests/SimpleBindingsTest.java @ 366:946d61915104 draft
Ten new tests added into SimpleBindingsTest.
author | ptisnovs |
---|---|
date | Fri, 23 May 2014 08:16:04 +0200 |
parents | 6f5566e8e8cf |
children |
line wrap: on
line source
/* Rhino test framework Copyright (C) 2011, 2012, 2013, 2014 Red Hat This file is part of IcedTea. IcedTea is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. IcedTea is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with IcedTea; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package org.RhinoTests; import java.util.HashMap; import java.util.TreeMap; import javax.script.SimpleBindings; /** * Basic SimpleBindings test suite. Following tests checks the class * javax.script.SimpleBindings. * * @author Pavel Tisnovsky */ public class SimpleBindingsTest 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 constructor without parameters. */ protected void testConstructor1() { SimpleBindings simpleBindings = new SimpleBindings(); assertNotNull(simpleBindings, "new SimpleBindings() failed"); assertTrue(simpleBindings.isEmpty(), "simpleBindings should be empty"); assertTrue(simpleBindings.size() == 0, "simpleBindings should be empty"); } /** * Test for constructor with the parameter Map<String,Object> */ protected void testConstructor2() { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); assertNotNull(simpleBindings, "new SimpleBindings() failed"); assertTrue(simpleBindings.isEmpty(), "simpleBindings should be empty"); assertTrue(simpleBindings.size() == 0, "simpleBindings should be empty"); } /** * Test for constructor with the parameter Map<String,Object> */ protected void testConstructor3() { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); assertNotNull(simpleBindings, "new SimpleBindings() failed"); assertTrue(simpleBindings.isEmpty(), "simpleBindings should be empty"); assertTrue(simpleBindings.size() == 0, "simpleBindings should be empty"); } /** * Test for method containsKey(String) */ protected void testContainsKey1() { SimpleBindings simpleBindings = new SimpleBindings(); assertFalse(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKey2() { SimpleBindings simpleBindings = new SimpleBindings(); simpleBindings.put("key", "value"); assertTrue(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKey3() { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); assertFalse(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKey4() { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); simpleBindings.put("key", "value"); assertTrue(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKey5() { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); assertFalse(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKey6() { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); simpleBindings.put("key", "value"); assertTrue(simpleBindings.containsKey("key"), "Bingings.containsKey() failed"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative1() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(); try { simpleBindings.containsKey(null); } catch (NullPointerException e) { return; } throw new Exception("NPE did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative2() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(); try { simpleBindings.containsKey(""); } catch (IllegalArgumentException e) { return; } throw new Exception("IllegalArgumentException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative3() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(); try { simpleBindings.containsKey(new Integer(42)); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative4() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(); try { simpleBindings.containsKey(java.awt.Color.GREEN); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative5() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(); try { simpleBindings.containsKey(this); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative6() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); try { simpleBindings.containsKey(null); } catch (NullPointerException e) { return; } throw new Exception("NPE did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative7() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); try { simpleBindings.containsKey(""); } catch (IllegalArgumentException e) { return; } throw new Exception("IllegalArgumentException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative8() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); try { simpleBindings.containsKey(new Integer(42)); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative9() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); try { simpleBindings.containsKey(java.awt.Color.GREEN); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative10() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new HashMap<String, Object>()); try { simpleBindings.containsKey(this); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative11() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); try { simpleBindings.containsKey(null); } catch (NullPointerException e) { return; } throw new Exception("NPE did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative12() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); try { simpleBindings.containsKey(""); } catch (IllegalArgumentException e) { return; } throw new Exception("IllegalArgumentException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative13() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); try { simpleBindings.containsKey(new Integer(42)); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative14() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); try { simpleBindings.containsKey(java.awt.Color.GREEN); } catch (ClassCastException e) { return; } throw new Exception("ClassCastException did not thrown as expected"); } /** * Test for method containsKey(String) */ protected void testContainsKeyNegative15() throws Exception { SimpleBindings simpleBindings = new SimpleBindings(new TreeMap<String, Object>()); try { simpleBindings.containsKey(this); } 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 SimpleBindingsTest().doTests(args); } }