KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nu > xom > tests > AttributesTest


1 /* Copyright 2002, 2003 Elliotte Rusty Harold
2    
3    This library is free software; you can redistribute it and/or modify
4    it under the terms of version 2.1 of the GNU Lesser General Public
5    License as published by the Free Software Foundation.
6    
7    This library is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    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 JavaDoc 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 JavaDoc success) {
67             assertNotNull(success.getMessage());
68         }
69         try {
70             threeAttributes.getAttribute(4);
71         }
72         catch (IndexOutOfBoundsException JavaDoc success) {
73             assertNotNull(success.getMessage());
74         }
75         try {
76             threeAttributes.getAttribute(-1);
77         }
78         catch (IndexOutOfBoundsException JavaDoc success) {
79             assertNotNull(success.getMessage());
80         }
81
82     }
83
84 }
Popular Tags