|
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 java.io.PrintWriter; |
|
25 |
| import java.io.StringWriter; |
|
26 |
| |
|
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; |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| public class XMLExceptionTest extends XOMTestCase { |
|
50 |
| |
|
51 |
| private XMLException ex; |
|
52 |
| private Exception cause; |
|
53 |
| private String message = "testing 1-2-3"; |
|
54 |
| |
|
55 |
17
| public XMLExceptionTest(String name) {
|
|
56 |
17
| super(name);
|
|
57 |
| } |
|
58 |
| |
|
59 |
| |
|
60 |
17
| protected void setUp() {
|
|
61 |
17
| ex = new XMLException("message");
|
|
62 |
17
| cause = new Exception();
|
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
1
| public void testConstructor() {
|
|
67 |
1
| XMLException ex = new XMLException(message, cause);
|
|
68 |
1
| assertEquals(message, ex.getMessage());
|
|
69 |
1
| assertEquals(cause, ex.getCause());
|
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
1
| public void testPrintStackTrace() {
|
|
74 |
1
| XMLException ex = new XMLException(message, cause);
|
|
75 |
1
| StringWriter out = new StringWriter();
|
|
76 |
1
| PrintWriter pw = new PrintWriter(out);
|
|
77 |
1
| ex.printStackTrace(pw);
|
|
78 |
1
| pw.close();
|
|
79 |
1
| assertTrue(out.toString().indexOf("Caused by: ") > 0);
|
|
80 |
| } |
|
81 |
| |
|
82 |
| |
|
83 |
1
| public void testMalformedURIExceptionConstructor() {
|
|
84 |
1
| XMLException ex = new MalformedURIException(message, cause);
|
|
85 |
1
| assertEquals(message, ex.getMessage());
|
|
86 |
1
| assertEquals(cause, ex.getCause());
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
1
| public void testValidityExceptionConstructor() {
|
|
91 |
1
| XMLException ex = new MalformedURIException(message, cause);
|
|
92 |
1
| assertEquals(message, ex.getMessage());
|
|
93 |
1
| assertEquals(cause, ex.getCause());
|
|
94 |
| } |
|
95 |
| |
|
96 |
| |
|
97 |
1
| public void testNamespaceConflictExceptionConstructor() {
|
|
98 |
1
| XMLException ex = new NamespaceConflictException(message, cause);
|
|
99 |
1
| assertEquals(message, ex.getMessage());
|
|
100 |
1
| assertEquals(cause, ex.getCause());
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
1
| public void testMultipleParentExceptionConstructor() {
|
|
105 |
1
| XMLException ex = new MultipleParentException(message, cause);
|
|
106 |
1
| assertEquals(message, ex.getMessage());
|
|
107 |
1
| assertEquals(cause, ex.getCause());
|
|
108 |
| } |
|
109 |
| |
|
110 |
| |
|
111 |
1
| public void testNoSuchAttributeExceptionConstructor() {
|
|
112 |
1
| XMLException ex = new NoSuchAttributeException(message, cause);
|
|
113 |
1
| assertEquals(message, ex.getMessage());
|
|
114 |
1
| assertEquals(cause, ex.getCause());
|
|
115 |
| } |
|
116 |
| |
|
117 |
| |
|
118 |
1
| public void testNoSuchChildExceptionConstructor() {
|
|
119 |
1
| XMLException ex = new NoSuchChildException(message, cause);
|
|
120 |
1
| assertEquals(message, ex.getMessage());
|
|
121 |
1
| assertEquals(cause, ex.getCause());
|
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
1
| public void testCycleExceptionConstructor() {
|
|
126 |
1
| XMLException ex = new CycleException(message, cause);
|
|
127 |
1
| assertEquals(message, ex.getMessage());
|
|
128 |
1
| assertEquals(cause, ex.getCause());
|
|
129 |
| } |
|
130 |
| |
|
131 |
| |
|
132 |
1
| public void testIllegalNameExceptionConstructor() {
|
|
133 |
1
| XMLException ex = new IllegalNameException(message, cause);
|
|
134 |
1
| assertEquals(message, ex.getMessage());
|
|
135 |
1
| assertEquals(cause, ex.getCause());
|
|
136 |
| } |
|
137 |
| |
|
138 |
| |
|
139 |
1
| public void testIllegalTargetExceptionConstructor() {
|
|
140 |
1
| XMLException ex = new IllegalTargetException(message, cause);
|
|
141 |
1
| assertEquals(message, ex.getMessage());
|
|
142 |
1
| assertEquals(cause, ex.getCause());
|
|
143 |
| } |
|
144 |
| |
|
145 |
| |
|
146 |
1
| public void testIllegalAddExceptionConstructor() {
|
|
147 |
1
| XMLException ex = new IllegalAddException(message, cause);
|
|
148 |
1
| assertEquals(message, ex.getMessage());
|
|
149 |
1
| assertEquals(cause, ex.getCause());
|
|
150 |
| } |
|
151 |
| |
|
152 |
| |
|
153 |
1
| public void testIllegalDataExceptionConstructor() {
|
|
154 |
1
| XMLException ex = new IllegalDataException(message, cause);
|
|
155 |
1
| assertEquals(message, ex.getMessage());
|
|
156 |
1
| assertEquals(cause, ex.getCause());
|
|
157 |
| } |
|
158 |
| |
|
159 |
1
| public void testInitCause() {
|
|
160 |
| |
|
161 |
1
| assertNull(ex.getCause());
|
|
162 |
1
| ex.initCause(cause);
|
|
163 |
1
| assertEquals(cause, ex.getCause());
|
|
164 |
| |
|
165 |
1
| try {
|
|
166 |
1
| ex.initCause(null);
|
|
167 |
0
| fail("Reinitialized cause over null");
|
|
168 |
| } |
|
169 |
| catch (IllegalStateException result) { |
|
170 |
| |
|
171 |
| } |
|
172 |
| |
|
173 |
1
| try {
|
|
174 |
1
| ex.initCause(new Exception());
|
|
175 |
0
| fail("Reinitialized cause over null");
|
|
176 |
| } |
|
177 |
| catch (IllegalStateException result) { |
|
178 |
| |
|
179 |
| } |
|
180 |
| |
|
181 |
| } |
|
182 |
| |
|
183 |
| |
|
184 |
1
| public void testNullInitCause() {
|
|
185 |
| |
|
186 |
1
| ex = new XMLException(null, null);
|
|
187 |
1
| assertNull(ex.getCause());
|
|
188 |
| |
|
189 |
1
| try {
|
|
190 |
1
| ex.initCause(new Exception());
|
|
191 |
0
| fail("Reinitialized cause over null");
|
|
192 |
| } |
|
193 |
| catch (IllegalStateException result) { |
|
194 |
| |
|
195 |
| } |
|
196 |
| |
|
197 |
1
| try {
|
|
198 |
1
| ex.initCause(null);
|
|
199 |
0
| fail("Reinitialized cause over null");
|
|
200 |
| } |
|
201 |
| catch (IllegalStateException result) { |
|
202 |
| |
|
203 |
| } |
|
204 |
| |
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
1
| public void testSelfCause() {
|
|
209 |
| |
|
210 |
1
| try {
|
|
211 |
1
| ex.initCause(ex);
|
|
212 |
0
| fail("Allowed self-causation");
|
|
213 |
| } |
|
214 |
| catch (IllegalArgumentException result) { |
|
215 |
| |
|
216 |
| } |
|
217 |
| |
|
218 |
| } |
|
219 |
| |
|
220 |
| |
|
221 |
1
| public void testGetMessage() {
|
|
222 |
1
| Exception ex = new XMLException("testing");
|
|
223 |
1
| assertEquals("testing", ex.getMessage());
|
|
224 |
| } |
|
225 |
| |
|
226 |
| |
|
227 |
| } |