KickJava   Java API By Example, From Geeks To Geeks.

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


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.ParsingException;
25 import nu.xom.ValidityException;
26
27 /**
28  * <p>
29  * Unit tests for the <code>ValidityException</code> class.
30  * </p>
31  *
32  * @author Elliotte Rusty Harold
33  * @version 1.0
34  *
35  */

36 public class ValidityExceptionTest extends XOMTestCase {
37     
38     
39     private ValidityException ex = new ValidityException("message");
40     private Exception JavaDoc cause = new Exception JavaDoc();
41     private String JavaDoc message = "testing 1-2-3";
42     
43     
44     public ValidityExceptionTest(String JavaDoc name) {
45         super(name);
46     }
47
48     
49     public void testConstructor() {
50         ParsingException ex = new ValidityException(message, cause);
51         assertEquals(message, ex.getMessage());
52         assertEquals(cause, ex.getCause());
53     }
54     
55     
56     public void testFourArgumentConstructor() {
57             
58         ParsingException ex = new ValidityException(message, 10000, 40000, cause);
59         assertEquals(message, ex.getMessage());
60         assertEquals(cause, ex.getCause());
61         assertEquals(10000, ex.getLineNumber());
62         assertEquals(40000, ex.getColumnNumber());
63
64     }
65     
66     
67     public void testAnotherFourArgumentConstructor() {
68             
69         ParsingException ex = new ValidityException(
70           message, "http://www.example.com/", 10000, 40000);
71         assertEquals(message, ex.getMessage());
72         assertNull(ex.getCause());
73         assertEquals(10000, ex.getLineNumber());
74         assertEquals(40000, ex.getColumnNumber());
75         assertEquals("http://www.example.com/", ex.getURI());
76         
77     }
78     
79     
80     public void testLineAndColumnNumbers() {
81         
82         ValidityException ex = new ValidityException(message, 10, 20);
83         assertEquals(message, ex.getMessage());
84         assertNull(ex.getCause());
85         assertEquals(10, ex.getLineNumber());
86         assertEquals(20, ex.getColumnNumber());
87         
88     }
89     
90     
91     public void testInitCause() {
92         
93         assertNull(ex.getCause());
94         ex.initCause(cause);
95         assertEquals(cause, ex.getCause());
96         
97         try {
98             ex.initCause(null);
99             fail("Reinitialized cause over null");
100         }
101         catch (IllegalStateException JavaDoc success) {
102             // success
103
}
104         
105         try {
106             ex.initCause(new Exception JavaDoc());
107             fail("Reinitialized cause over null");
108         }
109         catch (IllegalStateException JavaDoc success) {
110             // success
111
}
112         
113     }
114
115
116     public void testNullInitCause() {
117         
118         ValidityException ex = new ValidityException(null, null);
119         assertNull(ex.getCause());
120         assertNull(ex.getMessage());
121         assertEquals(-1, ex.getLineNumber());
122         assertEquals(-1, ex.getColumnNumber());
123         
124         try {
125             ex.initCause(new Exception JavaDoc());
126             fail("Reinitialized cause over null");
127         }
128         catch (IllegalStateException JavaDoc result) {
129             // success
130
}
131
132         try {
133             ex.initCause(null);
134             fail("Reinitialized cause over null");
135         }
136         catch (IllegalStateException JavaDoc result) {
137             // success
138
}
139         
140     }
141
142     
143     public void testSelfCause() {
144         
145         try {
146             ex.initCause(ex);
147             fail("Allowed self-causation");
148         }
149         catch (IllegalArgumentException JavaDoc result) {
150             // success
151
}
152         
153     }
154
155     
156     public void testGetMessage() {
157         Exception JavaDoc ex = new ValidityException("testing");
158         assertEquals("testing", ex.getMessage());
159     }
160
161     
162 }
163
Popular Tags