KickJava   Java API By Example, From Geeks To Geeks.

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


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

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