KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* Copyright 2003, 2004 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.CycleException;
25 import nu.xom.IllegalAddException;
26 import nu.xom.IllegalDataException;
27 import nu.xom.IllegalNameException;
28 import nu.xom.IllegalTargetException;
29 import nu.xom.MalformedURIException;
30 import nu.xom.MultipleParentException;
31 import nu.xom.NamespaceConflictException;
32 import nu.xom.NoSuchAttributeException;
33 import nu.xom.NoSuchChildException;
34 import nu.xom.XMLException;
35
36 /**
37  * <p>
38  * This class provides unit tests for the <code>XMLException</code>
39  * class.
40  * </p>
41  *
42  * @author Elliotte Rusty Harold
43  * @version 1.0
44  *
45  */

46 public class XMLExceptionTest extends XOMTestCase {
47     
48     private XMLException ex;
49     private Exception JavaDoc cause;
50     private String JavaDoc message = "testing 1-2-3";
51     
52     public XMLExceptionTest(String JavaDoc name) {
53         super(name);
54     }
55
56     
57     protected void setUp() {
58         ex = new XMLException("message");
59         cause = new Exception JavaDoc();
60     }
61
62     
63     public void testConstructor() {
64         XMLException ex = new XMLException(message, cause);
65         assertEquals(message, ex.getMessage());
66         assertEquals(cause, ex.getCause());
67     }
68     
69     
70     public void testMalformedURIExceptionConstructor() {
71         XMLException ex = new MalformedURIException(message, cause);
72         assertEquals(message, ex.getMessage());
73         assertEquals(cause, ex.getCause());
74     }
75     
76     
77     public void testValidityExceptionConstructor() {
78         XMLException ex = new MalformedURIException(message, cause);
79         assertEquals(message, ex.getMessage());
80         assertEquals(cause, ex.getCause());
81     }
82     
83     
84     public void testNamespaceConflictExceptionConstructor() {
85         XMLException ex = new NamespaceConflictException(message, cause);
86         assertEquals(message, ex.getMessage());
87         assertEquals(cause, ex.getCause());
88     }
89     
90     
91     public void testMultipleParentExceptionConstructor() {
92         XMLException ex = new MultipleParentException(message, cause);
93         assertEquals(message, ex.getMessage());
94         assertEquals(cause, ex.getCause());
95     }
96     
97     
98     public void testNoSuchAttributeExceptionConstructor() {
99         XMLException ex = new NoSuchAttributeException(message, cause);
100         assertEquals(message, ex.getMessage());
101         assertEquals(cause, ex.getCause());
102     }
103     
104     
105     public void testNoSuchChildExceptionConstructor() {
106         XMLException ex = new NoSuchChildException(message, cause);
107         assertEquals(message, ex.getMessage());
108         assertEquals(cause, ex.getCause());
109     }
110     
111     
112     public void testCycleExceptionConstructor() {
113         XMLException ex = new CycleException(message, cause);
114         assertEquals(message, ex.getMessage());
115         assertEquals(cause, ex.getCause());
116     }
117     
118     
119     public void testIllegalNameExceptionConstructor() {
120         XMLException ex = new IllegalNameException(message, cause);
121         assertEquals(message, ex.getMessage());
122         assertEquals(cause, ex.getCause());
123     }
124     
125     
126     public void testIllegalTargetExceptionConstructor() {
127         XMLException ex = new IllegalTargetException(message, cause);
128         assertEquals(message, ex.getMessage());
129         assertEquals(cause, ex.getCause());
130     }
131     
132     
133     public void testIllegalAddExceptionConstructor() {
134         XMLException ex = new IllegalAddException(message, cause);
135         assertEquals(message, ex.getMessage());
136         assertEquals(cause, ex.getCause());
137     }
138     
139     
140     public void testIllegalDataExceptionConstructor() {
141         XMLException ex = new IllegalDataException(message, cause);
142         assertEquals(message, ex.getMessage());
143         assertEquals(cause, ex.getCause());
144     }
145     
146     public void testInitCause() {
147         
148         assertNull(ex.getCause());
149         ex.initCause(cause);
150         assertEquals(cause, ex.getCause());
151         
152         try {
153             ex.initCause(null);
154             fail("Reinitialized cause over null");
155         }
156         catch (IllegalStateException JavaDoc result) {
157             // success
158
}
159         
160         try {
161             ex.initCause(new Exception JavaDoc());
162             fail("Reinitialized cause over null");
163         }
164         catch (IllegalStateException JavaDoc result) {
165             // success
166
}
167         
168     }
169
170
171     public void testNullInitCause() {
172         
173         ex = new XMLException(null, null);
174         assertNull(ex.getCause());
175         
176         try {
177             ex.initCause(new Exception JavaDoc());
178             fail("Reinitialized cause over null");
179         }
180         catch (IllegalStateException JavaDoc result) {
181             // success
182
}
183
184         try {
185             ex.initCause(null);
186             fail("Reinitialized cause over null");
187         }
188         catch (IllegalStateException JavaDoc result) {
189             // success
190
}
191         
192     }
193
194     
195     public void testSelfCause() {
196         
197         try {
198             ex.initCause(ex);
199             fail("Allowed self-causation");
200         }
201         catch (IllegalArgumentException JavaDoc result) {
202             // success
203
}
204         
205     }
206
207     
208     public void testGetMessage() {
209         Exception JavaDoc ex = new XMLException("testing");
210         assertEquals("testing", ex.getMessage());
211     }
212
213     
214 }
215
Popular Tags