Revision: 564 Author: allain.lalonde Date: Sat Jul 25 17:43:19 2009 Log: Broke apart the name tests so that 1 test method tested 1 obvious behaviour http://code.google.com/p/piccolo2d/source/detail?r=564
Modified: /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java ======================================= --- /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java Sat Jul 25 06:11:25 2009 +++ /piccolo2d.java/trunk/core/src/test/java/edu/umd/cs/piccolo/PNodeTest.java Sat Jul 25 17:43:19 2009 @@ -76,35 +76,77 @@ mockListener = new MockPropertyChangeListener(); } - public void testSetName() { - PNode n = new PNode(null); - n.setName("_."); - assertEquals("_.", n.getName()); - n.setName("_-"); - assertEquals("_-", n.getName()); + public void testDefaultNameIsNull() { + assertNull(node.getName()); + } + + public void testConstructorWithNameAcceptsNull() { + node = new PNode(null); + assertNull(node.getName()); + } + + public void testConstructorWithInvaliNameThrowsException() { try { - n.setName("-_"); + node = new PNode("-_"); + fail("Invalid name for constructor should throw exception"); + } + catch (IllegalArgumentException e) { + // expected + } + } + + public void testSetNamePersists() { + node.setName("name"); + assertEquals("name", node.getName()); + } + + public void testNameMayContainPeriods() { + node.setName("_."); + assertEquals("_.", node.getName()); + } + + public void testNameMayStartWithUnderscore() { + node.setName("_-"); + assertEquals("_-", node.getName()); + } + + public void testNameMayNotStartWithDash() { + try { + node.setName("-_"); fail(); } catch (IllegalArgumentException e) { - } + // expected + } + } + + public void testNameMayNotBeEmptyString() { try { - n.setName(""); + node.setName(""); fail(); } catch (IllegalArgumentException e) { - } + // expected + } + } + + public void testNameMayNotContainColons() { try { - n.setName("a:b"); + node.setName("a:b"); fail(); } catch (IllegalArgumentException e) { - } + // expected + } + } + + public void testNameMayNotStartWithADigit() { try { - n.setName("0name"); + node.setName("0name"); fail(); } catch (IllegalArgumentException e) { + // expected } } --~--~---------~--~----~------------~-------~--~----~ Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en -~----------~----~----~----~------~----~------~--~---