|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| package nu.xom.tests; |
|
23 |
| |
|
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; |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| public class XIncludeExceptionTest extends XOMTestCase { |
|
40 |
| |
|
41 |
| private XIncludeException ex; |
|
42 |
| private Exception cause; |
|
43 |
| |
|
44 |
| |
|
45 |
9
| public XIncludeExceptionTest(String name) {
|
|
46 |
9
| super(name);
|
|
47 |
| } |
|
48 |
| |
|
49 |
| |
|
50 |
9
| protected void setUp() {
|
|
51 |
9
| ex = new XIncludeException("message");
|
|
52 |
9
| cause = new Exception();
|
|
53 |
| } |
|
54 |
| |
|
55 |
| |
|
56 |
1
| public void testConstructor() {
|
|
57 |
1
| ex = new XIncludeException("test", "http://ex.com/");
|
|
58 |
1
| assertEquals("test", ex.getMessage());
|
|
59 |
1
| assertEquals("http://ex.com/", ex.getURI());
|
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
1
| public void testInitCause() {
|
|
64 |
| |
|
65 |
1
| assertNull(ex.getCause());
|
|
66 |
1
| ex.initCause(cause);
|
|
67 |
1
| assertEquals(cause, ex.getCause());
|
|
68 |
| |
|
69 |
1
| try {
|
|
70 |
1
| ex.initCause(null);
|
|
71 |
0
| fail("Reinitialized cause over null");
|
|
72 |
| } |
|
73 |
| catch (IllegalStateException result) { |
|
74 |
| |
|
75 |
| } |
|
76 |
| |
|
77 |
1
| try {
|
|
78 |
1
| ex.initCause(new Exception());
|
|
79 |
0
| fail("Reinitialized cause over null");
|
|
80 |
| } |
|
81 |
| catch (IllegalStateException result) { |
|
82 |
| |
|
83 |
| } |
|
84 |
| |
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
1
| public void testNullInitCause() {
|
|
89 |
| |
|
90 |
1
| XIncludeException ex
|
|
91 |
| = new XIncludeException("message", (Exception) null); |
|
92 |
1
| assertNull(ex.getCause());
|
|
93 |
| |
|
94 |
1
| try {
|
|
95 |
1
| ex.initCause(new Exception());
|
|
96 |
0
| fail("Reinitialized cause over null");
|
|
97 |
| } |
|
98 |
| catch (IllegalStateException result) { |
|
99 |
| |
|
100 |
| } |
|
101 |
| |
|
102 |
1
| try {
|
|
103 |
1
| ex.initCause(null);
|
|
104 |
0
| fail("Reinitialized cause over null");
|
|
105 |
| } |
|
106 |
| catch (IllegalStateException result) { |
|
107 |
| |
|
108 |
| } |
|
109 |
| |
|
110 |
| } |
|
111 |
| |
|
112 |
| |
|
113 |
1
| public void testSelfCause() {
|
|
114 |
| |
|
115 |
1
| try {
|
|
116 |
1
| ex.initCause(ex);
|
|
117 |
0
| fail("Allowed self-causation");
|
|
118 |
| } |
|
119 |
| catch (IllegalArgumentException success) { |
|
120 |
| |
|
121 |
| } |
|
122 |
| |
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
1
| public void testGetMessage() {
|
|
127 |
1
| Exception ex = new XIncludeException("testing");
|
|
128 |
1
| assertEquals("testing", ex.getMessage());
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
1
| public void testMisplacedFallbackException() {
|
|
133 |
1
| String message = "message";
|
|
134 |
1
| Exception ex = new MisplacedFallbackException(message);
|
|
135 |
1
| assertEquals(message, ex.getMessage());
|
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
1
| public void testBadParseAttributeException() {
|
|
140 |
1
| String message = "message";
|
|
141 |
1
| Exception ex = new BadParseAttributeException(message);
|
|
142 |
1
| assertEquals(message, ex.getMessage());
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
1
| public void testBadEncodingAttributeException() {
|
|
147 |
1
| String message = "message";
|
|
148 |
1
| Exception ex = new BadEncodingAttributeException(message);
|
|
149 |
1
| assertEquals(message, ex.getMessage());
|
|
150 |
| } |
|
151 |
| |
|
152 |
| |
|
153 |
1
| public void testNoIncludeLocationException() {
|
|
154 |
| |
|
155 |
1
| String message = "message";
|
|
156 |
1
| XIncludeException ex = new NoIncludeLocationException(message);
|
|
157 |
1
| assertEquals(message, ex.getMessage());
|
|
158 |
1
| assertNull(ex.getCause());
|
|
159 |
| |
|
160 |
1
| Exception cause = new Exception();
|
|
161 |
1
| ex = new NoIncludeLocationException(message, cause);
|
|
162 |
1
| assertEquals(message, ex.getMessage());
|
|
163 |
1
| assertEquals(cause, ex.getCause());
|
|
164 |
| |
|
165 |
| } |
|
166 |
| |
|
167 |
| } |