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;
25
import nu.xom.ValidityException;
29
* Unit tests for the <code>ValidityException</code> class.
32
* @author Elliotte Rusty Harold
36
public class ValidityExceptionTest extends XOMTestCase {
39
private ValidityException ex = new ValidityException("message");
40
private Exception cause = new Exception();
41
private String message = "testing 1-2-3";
44
public ValidityExceptionTest(String name) {
49
public void testConstructor() {
50
ParsingException ex = new ValidityException(message, cause);
51
assertEquals(message, ex.getMessage());
52
assertEquals(cause, ex.getCause());
56
public void testFourArgumentConstructor() {
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());
67
public void testAnotherFourArgumentConstructor() {
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());
80
public void testLineAndColumnNumbers() {
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());
91
public void testInitCause() {
93
assertNull(ex.getCause());
95
assertEquals(cause, ex.getCause());
99
fail("Reinitialized cause over null");
101
catch (IllegalStateException success) {
106
ex.initCause(new Exception());
107
fail("Reinitialized cause over null");
109
catch (IllegalStateException success) {
116
public void testNullInitCause() {
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());
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 ValidityException("testing");
158
assertEquals("testing", ex.getMessage());