1
/* Copyright 2003-2005 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.xinclude.BadEncodingAttributeException;
25
import nu.xom.xinclude.BadParseAttributeException;
26
import nu.xom.xinclude.MisplacedFallbackException;
27
import nu.xom.xinclude.NoIncludeLocationException;
28
import nu.xom.xinclude.XIncludeException;
32
* Unit tests for the <code>XIncludeException</code> class.
35
* @author Elliotte Rusty Harold
39
public class XIncludeExceptionTest extends XOMTestCase {
41
private XIncludeException ex;
42
private Exception cause;
45
public XIncludeExceptionTest(String name) {
50
protected void setUp() {
51
ex = new XIncludeException("message");
52
cause = new Exception();
56
public void testConstructor() {
57
ex = new XIncludeException("test", "http://ex.com/");
58
assertEquals("test", ex.getMessage());
59
assertEquals("http://ex.com/", ex.getURI());
63
public void testInitCause() {
65
assertNull(ex.getCause());
67
assertEquals(cause, ex.getCause());
71
fail("Reinitialized cause over null");
73
catch (IllegalStateException result) {
78
ex.initCause(new Exception());
79
fail("Reinitialized cause over null");
81
catch (IllegalStateException result) {
88
public void testNullInitCause() {
91
= new XIncludeException("message", (Exception) null);
92
assertNull(ex.getCause());
95
ex.initCause(new Exception());
96
fail("Reinitialized cause over null");
98
catch (IllegalStateException result) {
104
fail("Reinitialized cause over null");
106
catch (IllegalStateException result) {
113
public void testSelfCause() {
117
fail("Allowed self-causation");
119
catch (IllegalArgumentException success) {
126
public void testGetMessage() {
127
Exception ex = new XIncludeException("testing");
128
assertEquals("testing", ex.getMessage());
132
public void testMisplacedFallbackException() {
133
String message = "message";
134
Exception ex = new MisplacedFallbackException(message);
135
assertEquals(message, ex.getMessage());
139
public void testBadParseAttributeException() {
140
String message = "message";
141
Exception ex = new BadParseAttributeException(message);
142
assertEquals(message, ex.getMessage());
146
public void testBadEncodingAttributeException() {
147
String message = "message";
148
Exception ex = new BadEncodingAttributeException(message);
149
assertEquals(message, ex.getMessage());
153
public void testNoIncludeLocationException() {
155
String message = "message";
156
XIncludeException ex = new NoIncludeLocationException(message);
157
assertEquals(message, ex.getMessage());
158
assertNull(ex.getCause());
160
Exception cause = new Exception();
161
ex = new NoIncludeLocationException(message, cause);
162
assertEquals(message, ex.getMessage());
163
assertEquals(cause, ex.getCause());