From: Astrid S. <ast...@us...> - 2008-01-18 19:26:35
|
Update of /cvsroot/arianne/marauroa/tests/marauroa/common/game In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv13107/tests/marauroa/common/game Modified Files: RPObjectTest.java Log Message: protect hasSlot against passed in NULL Index: RPObjectTest.java =================================================================== RCS file: /cvsroot/arianne/marauroa/tests/marauroa/common/game/RPObjectTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RPObjectTest.java 11 Dec 2007 19:42:36 -0000 1.3 --- RPObjectTest.java 18 Jan 2008 19:26:38 -0000 1.4 *************** *** 21,25 **** /** ! * Test unit for RPObject basic functionality * * @author miguel --- 21,25 ---- /** ! * Test unit for RPObject basic functionality. * * @author miguel *************** *** 118,122 **** @Test public void testHasAsParent() { ! RPObject p=obj.getSlot("lhand").getFirst(); assertTrue(obj.getSlot("lhand").hasAsAncestor(obj)); --- 118,122 ---- @Test public void testHasAsParent() { ! RPObject p = obj.getSlot("lhand").getFirst(); assertTrue(obj.getSlot("lhand").hasAsAncestor(obj)); *************** *** 124,140 **** } ! @Test(expected=SlotIsFullException.class) public void testSlotCapacity() { ! RPClass clazz=new RPClass("object"); clazz.addAttribute("a", Type.BYTE); clazz.addRPSlot("cont", 1); ! ! obj=new RPObject(); obj.setRPClass("object"); obj.addSlot("cont"); ! ! RPSlot s=obj.getSlot("cont"); s.add(new RPObject()); ! s.add(new RPObject()); fail("Object added"); --- 124,140 ---- } ! @Test(expected = SlotIsFullException.class) public void testSlotCapacity() { ! RPClass clazz = new RPClass("object"); clazz.addAttribute("a", Type.BYTE); clazz.addRPSlot("cont", 1); ! ! obj = new RPObject(); obj.setRPClass("object"); obj.addSlot("cont"); ! ! RPSlot s = obj.getSlot("cont"); s.add(new RPObject()); ! s.add(new RPObject()); fail("Object added"); *************** *** 160,168 **** /** ! * Test serialization of the RPObject by serializing it and then * deserializing it from the stream back again. * * @throws IOException - * @throws ClassNotFoundException */ @Test --- 160,167 ---- /** ! * Tests serialization of the RPObject by serializing it and then * deserializing it from the stream back again. * * @throws IOException */ @Test *************** *** 201,208 **** public void testGetObjectFromSlots() { RPObject coin = obj.getSlot("lhand").getFirst().getSlot("container").getFirst(); ! ! RPObject coinfromslot=obj.getFromSlots(coin.getInt("id")); ! assertEquals(coin,coinfromslot); ! assertNull(obj.getFromSlots(-1)); } --- 200,207 ---- public void testGetObjectFromSlots() { RPObject coin = obj.getSlot("lhand").getFirst().getSlot("container").getFirst(); ! ! RPObject coinfromslot = obj.getFromSlots(coin.getInt("id")); ! assertEquals(coin, coinfromslot); ! assertNull(obj.getFromSlots(-1)); } *************** *** 239,242 **** --- 238,259 ---- assertTrue(odeleted.isEmpty()); } + + /** + * Checks that passing <code>null</code> does not throw a NPE. + */ + @Test + public void testhasSlot() { + RPObject localobj = new RPObject(); + String slotname = "slotname"; + assertFalse(localobj.hasSlot(slotname)); + assertFalse(localobj.hasSlot(slotname + "blabla")); + assertFalse(localobj.hasSlot(null)); + + localobj.addSlot(slotname); + assertTrue(localobj.hasSlot(slotname)); + assertFalse(localobj.hasSlot(slotname + "blabla")); + assertFalse(localobj.hasSlot(null)); + + } } |