01: /* Copyright 2002, 2003 Elliotte Rusty Harold
02:
03: This library is free software; you can redistribute it and/or modify
04: it under the terms of version 2.1 of the GNU Lesser General Public
05: License as published by the Free Software Foundation.
06:
07: This library is distributed in the hope that it will be useful,
08: but WITHOUT ANY WARRANTY; without even the implied warranty of
09: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: GNU Lesser General Public License for more details.
11:
12: You should have received a copy of the GNU Lesser General Public
13: License along with this library; if not, write to the
14: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15: Boston, MA 02111-1307 USA
16:
17: You can contact Elliotte Rusty Harold by sending e-mail to
18: elharo@metalab.unc.edu. Please include the word "XOM" in the
19: subject line. The XOM home page is located at http://www.xom.nu/
20: */
21:
22: package nu.xom.tests;
23:
24: import nu.xom.Attribute;
25: import nu.xom.Element;
26:
27: /**
28: * <p>
29: * This class provides unit tests for the
30: * <code>Attributes</code> class.
31: * </p>
32: *
33: * @author Elliotte Rusty Harold
34: * @version 1.0
35: *
36: */
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: protected void setUp() {
47: noAttributes = new Element("test");
48: threeAttributes = new Element("test");
49: threeAttributes.addAttribute(new Attribute("att1", "value1"));
50: threeAttributes.addAttribute(new Attribute("att2", "value2"));
51: threeAttributes.addAttribute(new Attribute("att3", "value3"));
52: }
53:
54: public void testSize() {
55: assertEquals(0, noAttributes.getAttributeCount());
56: assertEquals(3, threeAttributes.getAttributeCount());
57: }
58:
59: public void testGetOutOfBounds() {
60:
61: try {
62: noAttributes.getAttribute(0);
63: fail("Should have thrown IndexOutOfBoundsException");
64: } catch (IndexOutOfBoundsException success) {
65: assertNotNull(success.getMessage());
66: }
67: try {
68: threeAttributes.getAttribute(4);
69: } catch (IndexOutOfBoundsException success) {
70: assertNotNull(success.getMessage());
71: }
72: try {
73: threeAttributes.getAttribute(-1);
74: } catch (IndexOutOfBoundsException success) {
75: assertNotNull(success.getMessage());
76: }
77:
78: }
79:
80: }
|