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 java.io.PrintWriter;
25
import java.io.StringWriter;
27
import nu.xom.CycleException;
28
import nu.xom.IllegalAddException;
29
import nu.xom.IllegalDataException;
30
import nu.xom.IllegalNameException;
31
import nu.xom.IllegalTargetException;
32
import nu.xom.MalformedURIException;
33
import nu.xom.MultipleParentException;
34
import nu.xom.NamespaceConflictException;
35
import nu.xom.NoSuchAttributeException;
36
import nu.xom.NoSuchChildException;
37
import nu.xom.XMLException;
41
* This class provides unit tests for the <code>XMLException</code>
45
* @author Elliotte Rusty Harold
49
public class XMLExceptionTest extends XOMTestCase {
51
private XMLException ex;
52
private Exception cause;
53
private String message = "testing 1-2-3";
55
public XMLExceptionTest(String name) {
60
protected void setUp() {
61
ex = new XMLException("message");
62
cause = new Exception();
66
public void testConstructor() {
67
XMLException ex = new XMLException(message, cause);
68
assertEquals(message, ex.getMessage());
69
assertEquals(cause, ex.getCause());
73
public void testPrintStackTrace() {
74
XMLException ex = new XMLException(message, cause);
75
StringWriter out = new StringWriter();
76
PrintWriter pw = new PrintWriter(out);
77
ex.printStackTrace(pw);
79
assertTrue(out.toString().indexOf("Caused by: ") > 0);
83
public void testMalformedURIExceptionConstructor() {
84
XMLException ex = new MalformedURIException(message, cause);
85
assertEquals(message, ex.getMessage());
86
assertEquals(cause, ex.getCause());
90
public void testValidityExceptionConstructor() {
91
XMLException ex = new MalformedURIException(message, cause);
92
assertEquals(message, ex.getMessage());
93
assertEquals(cause, ex.getCause());
97
public void testNamespaceConflictExceptionConstructor() {
98
XMLException ex = new NamespaceConflictException(message, cause);
99
assertEquals(message, ex.getMessage());
100
assertEquals(cause, ex.getCause());
104
public void testMultipleParentExceptionConstructor() {
105
XMLException ex = new MultipleParentException(message, cause);
106
assertEquals(message, ex.getMessage());
107
assertEquals(cause, ex.getCause());
111
public void testNoSuchAttributeExceptionConstructor() {
112
XMLException ex = new NoSuchAttributeException(message, cause);
113
assertEquals(message, ex.getMessage());
114
assertEquals(cause, ex.getCause());
118
public void testNoSuchChildExceptionConstructor() {
119
XMLException ex = new NoSuchChildException(message, cause);
120
assertEquals(message, ex.getMessage());
121
assertEquals(cause, ex.getCause());
125
public void testCycleExceptionConstructor() {
126
XMLException ex = new CycleException(message, cause);
127
assertEquals(message, ex.getMessage());
128
assertEquals(cause, ex.getCause());
132
public void testIllegalNameExceptionConstructor() {
133
XMLException ex = new IllegalNameException(message, cause);
134
assertEquals(message, ex.getMessage());
135
assertEquals(cause, ex.getCause());
139
public void testIllegalTargetExceptionConstructor() {
140
XMLException ex = new IllegalTargetException(message, cause);
141
assertEquals(message, ex.getMessage());
142
assertEquals(cause, ex.getCause());
146
public void testIllegalAddExceptionConstructor() {
147
XMLException ex = new IllegalAddException(message, cause);
148
assertEquals(message, ex.getMessage());
149
assertEquals(cause, ex.getCause());
153
public void testIllegalDataExceptionConstructor() {
154
XMLException ex = new IllegalDataException(message, cause);
155
assertEquals(message, ex.getMessage());
156
assertEquals(cause, ex.getCause());
159
public void testInitCause() {
161
assertNull(ex.getCause());
163
assertEquals(cause, ex.getCause());
167
fail("Reinitialized cause over null");
169
catch (IllegalStateException result) {
174
ex.initCause(new Exception());
175
fail("Reinitialized cause over null");
177
catch (IllegalStateException result) {
184
public void testNullInitCause() {
186
ex = new XMLException(null, null);
187
assertNull(ex.getCause());
190
ex.initCause(new Exception());
191
fail("Reinitialized cause over null");
193
catch (IllegalStateException result) {
199
fail("Reinitialized cause over null");
201
catch (IllegalStateException result) {
208
public void testSelfCause() {
212
fail("Allowed self-causation");
214
catch (IllegalArgumentException result) {
221
public void testGetMessage() {
222
Exception ex = new XMLException("testing");
223
assertEquals("testing", ex.getMessage());