1
/* Copyright 2003, 2004 Elliotte Rusty Harold
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.
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.
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
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/
24
import nu.xom.ParsingException;
28
* Unit tests for the <code>ParsingException</code> class.
31
* @author Elliotte Rusty Harold
35
public class ParsingExceptionTest extends XOMTestCase {
38
private ParsingException ex;
39
private Exception cause;
40
private String message = "testing 1-2-3";
43
public ParsingExceptionTest(String name) {
48
protected void setUp() {
49
ex = new ParsingException("message");
50
cause = new Exception();
54
public void testConstructor() {
55
ParsingException ex = new ParsingException(message, cause);
56
assertEquals(message, ex.getMessage());
57
assertEquals(cause, ex.getCause());
61
public void testFourArgumentConstructor() {
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());
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());
81
public void testLineAndColumnNumbersInToString() {
82
ParsingException ex = new ParsingException(message, -1, -1);
83
String result = ex.toString();
84
assertEquals(-1, result.indexOf("-1"));
88
public void testToString() {
89
ParsingException ex = new ParsingException(message, 10, 20);
90
assertTrue(ex.toString().endsWith(" at line 10, column 20"));
94
public void testInitCause() {
96
assertNull(ex.getCause());
98
assertEquals(cause, ex.getCause());
102
fail("Reinitialized cause over null");
104
catch (IllegalStateException result) {
109
ex.initCause(new Exception());
110
fail("Reinitialized cause over null");
112
catch (IllegalStateException result) {
119
public void testNullInitCause() {
121
ParsingException ex = new ParsingException(null, null);
122
assertNull(ex.getCause());
125
ex.initCause(new Exception());
126
fail("Reinitialized cause over null");
128
catch (IllegalStateException result) {
134
fail("Reinitialized cause over null");
136
catch (IllegalStateException result) {
143
public void testSelfCause() {
147
fail("Allowed self-causation");
149
catch (IllegalArgumentException result) {
156
public void testGetMessage() {
157
Exception ex = new ParsingException("testing");
158
assertEquals("testing", ex.getMessage());
162
public void testGetURI() {
164
ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
165
assertEquals("http://www.example.org/", ex.getURI());
167
Exception cause = new Exception("test");
168
ex = new ParsingException("testing", "http://www.example.org/", 32, 24, cause);
169
assertEquals("http://www.example.org/", ex.getURI());
170
assertEquals(cause, ex.getCause());
175
public void testURIInToString() {
177
ParsingException ex = new ParsingException("testing", "http://www.example.org/", 32, 24);
178
assertTrue(ex.toString().indexOf("http://www.example.org/") > 1);