1 21 22 package nu.xom.tests; 23 24 import nu.xom.Attribute; 25 import nu.xom.Element; 26 27 37 public class AttributesTest extends XOMTestCase { 38 39 public AttributesTest(String name) { 40 super(name); 41 } 42 43 private Element threeAttributes; 44 private Element noAttributes; 45 46 47 protected void setUp() { 48 noAttributes = new Element("test"); 49 threeAttributes = new Element("test"); 50 threeAttributes.addAttribute(new Attribute("att1", "value1")); 51 threeAttributes.addAttribute(new Attribute("att2", "value2")); 52 threeAttributes.addAttribute(new Attribute("att3", "value3")); 53 } 54 55 public void testSize() { 56 assertEquals(0, noAttributes.getAttributeCount()); 57 assertEquals(3, threeAttributes.getAttributeCount()); 58 } 59 60 public void testGetOutOfBounds() { 61 62 try { 63 noAttributes.getAttribute(0); 64 fail("Should have thrown IndexOutOfBoundsException"); 65 } 66 catch (IndexOutOfBoundsException success) { 67 assertNotNull(success.getMessage()); 68 } 69 try { 70 threeAttributes.getAttribute(4); 71 } 72 catch (IndexOutOfBoundsException success) { 73 assertNotNull(success.getMessage()); 74 } 75 try { 76 threeAttributes.getAttribute(-1); 77 } 78 catch (IndexOutOfBoundsException success) { 79 assertNotNull(success.getMessage()); 80 } 81 82 } 83 84 } | Popular Tags |