1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.xml.tracker; |
17 |
|
|
18 |
|
import org.qedeq.base.test.QedeqTestCase; |
19 |
|
|
20 |
|
|
21 |
|
@link |
22 |
|
|
23 |
|
@version |
24 |
|
@author |
25 |
|
|
|
|
| 88.6% |
Uncovered Elements: 25 (220) |
Complexity: 35 |
Complexity Density: 0.17 |
|
26 |
|
public class SimpleXPathTest extends QedeqTestCase { |
27 |
|
|
28 |
|
|
29 |
|
private SimpleXPath object1; |
30 |
|
|
31 |
|
|
32 |
|
private SimpleXPath object2; |
33 |
|
|
34 |
|
|
35 |
|
private SimpleXPath object3; |
36 |
|
|
37 |
|
|
38 |
|
private SimpleXPath object4; |
39 |
|
|
40 |
|
|
41 |
|
private SimpleXPath object5; |
42 |
|
|
43 |
|
|
44 |
|
private SimpleXPath object6; |
45 |
|
|
46 |
|
|
47 |
|
private SimpleXPath object7; |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
49 |
8
|
protected void setUp() throws Exception {... |
50 |
8
|
super.setUp(); |
51 |
8
|
object1 = new SimpleXPath("/We/don't/need"); |
52 |
8
|
object2 = new SimpleXPath("/We/dont/need"); |
53 |
8
|
object3 = new SimpleXPath("/We/don't/need"); |
54 |
8
|
object4 = new SimpleXPath("/We/don't/need/no"); |
55 |
8
|
object5 = new SimpleXPath("/We/don't/need/no@education"); |
56 |
8
|
object6 = new SimpleXPath("/All/we[2]/need/is"); |
57 |
8
|
object7 = new SimpleXPath("/All/we/need/is[11]@love"); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
60 |
8
|
protected void tearDown() throws Exception {... |
61 |
8
|
super.tearDown(); |
62 |
8
|
object1 = null; |
63 |
8
|
object2 = null; |
64 |
8
|
object3 = null; |
65 |
8
|
object4 = null; |
66 |
8
|
object5 = null; |
67 |
8
|
object6 = null; |
68 |
8
|
object7 = null; |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
|
|
| 66.7% |
Uncovered Elements: 7 (21) |
Complexity: 8 |
Complexity Density: 0.38 |
1
PASS
|
|
74 |
1
|
public void testSimpleXPath() {... |
75 |
1
|
try { |
76 |
1
|
new SimpleXPath(""); |
77 |
0
|
fail("empty XPath is forbidden"); |
78 |
|
} catch (RuntimeException e) { |
79 |
|
|
80 |
|
} |
81 |
1
|
try { |
82 |
1
|
new SimpleXPath("no_absolute_path"); |
83 |
0
|
fail("relative path is forbidden"); |
84 |
|
} catch (RuntimeException e) { |
85 |
|
|
86 |
|
} |
87 |
1
|
try { |
88 |
1
|
new SimpleXPath("no_absolute_path"); |
89 |
0
|
fail("relative path is forbidden"); |
90 |
|
} catch (RuntimeException e) { |
91 |
|
|
92 |
|
} |
93 |
1
|
try { |
94 |
1
|
new SimpleXPath("/hello//again"); |
95 |
0
|
fail("empty element is forbidden"); |
96 |
|
} catch (RuntimeException e) { |
97 |
|
|
98 |
|
} |
99 |
1
|
try { |
100 |
1
|
new SimpleXPath("/hello/again/@"); |
101 |
0
|
fail("empty attribute is forbidden"); |
102 |
|
} catch (RuntimeException e) { |
103 |
|
|
104 |
|
} |
105 |
1
|
try { |
106 |
1
|
new SimpleXPath("/hello/again/"); |
107 |
0
|
fail("XPath should not end with /"); |
108 |
|
} catch (RuntimeException e) { |
109 |
|
|
110 |
|
} |
111 |
1
|
try { |
112 |
1
|
new SimpleXPath("/All/we[0]/have"); |
113 |
0
|
fail("element number must be greater than 0"); |
114 |
|
} catch (RuntimeException e) { |
115 |
|
|
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
@link |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
122 |
1
|
public void testSize() {... |
123 |
1
|
assertEquals(3, object1.size()); |
124 |
1
|
assertEquals(3, object2.size()); |
125 |
1
|
assertEquals(3, object3.size()); |
126 |
1
|
assertEquals(4, object4.size()); |
127 |
1
|
assertEquals(4, object5.size()); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
@link |
132 |
|
|
|
|
| 76.3% |
Uncovered Elements: 9 (38) |
Complexity: 10 |
Complexity Density: 0.26 |
1
PASS
|
|
133 |
1
|
public void testGetElementName() {... |
134 |
1
|
assertEquals("We", object1.getElementName(0)); |
135 |
1
|
assertEquals("don't", object1.getElementName(1)); |
136 |
1
|
assertEquals("need", object1.getElementName(2)); |
137 |
1
|
try { |
138 |
1
|
object1.getElementName(3); |
139 |
0
|
fail("getter should throw exception for access to non existent element"); |
140 |
|
} catch (RuntimeException e) { |
141 |
|
|
142 |
|
} |
143 |
1
|
try { |
144 |
1
|
object1.getElementName(-1); |
145 |
0
|
fail("getter should throw exception for access to non existent element"); |
146 |
|
} catch (RuntimeException e) { |
147 |
|
|
148 |
|
} |
149 |
1
|
try { |
150 |
1
|
object1.getElementName(11); |
151 |
0
|
fail("getter should throw exception for access to non existent element"); |
152 |
|
} catch (RuntimeException e) { |
153 |
|
|
154 |
|
} |
155 |
1
|
assertEquals("We", object4.getElementName(0)); |
156 |
1
|
assertEquals("don't", object4.getElementName(1)); |
157 |
1
|
assertEquals("need", object4.getElementName(2)); |
158 |
1
|
assertEquals("no", object4.getElementName(3)); |
159 |
1
|
try { |
160 |
1
|
object4.getElementName(4); |
161 |
0
|
fail("getter should throw exception for access to non existent element"); |
162 |
|
} catch (RuntimeException e) { |
163 |
|
|
164 |
|
} |
165 |
1
|
try { |
166 |
1
|
object4.getElementName(-1); |
167 |
0
|
fail("getter should throw exception for access to non existent element"); |
168 |
|
} catch (RuntimeException e) { |
169 |
|
|
170 |
|
} |
171 |
1
|
try { |
172 |
1
|
object4.getElementName(11); |
173 |
0
|
fail("getter should throw exception for access to non existent element"); |
174 |
|
} catch (RuntimeException e) { |
175 |
|
|
176 |
|
} |
177 |
1
|
assertEquals("All", object7.getElementName(0)); |
178 |
1
|
assertEquals("we", object7.getElementName(1)); |
179 |
1
|
assertEquals("need", object7.getElementName(2)); |
180 |
1
|
assertEquals("is", object7.getElementName(3)); |
181 |
1
|
try { |
182 |
1
|
object7.getElementName(4); |
183 |
0
|
fail("getter should throw exception for access to non existent element"); |
184 |
|
} catch (RuntimeException e) { |
185 |
|
|
186 |
|
} |
187 |
1
|
try { |
188 |
1
|
object7.getElementName(-1); |
189 |
0
|
fail("getter should throw exception for access to non existent element"); |
190 |
|
} catch (RuntimeException e) { |
191 |
|
|
192 |
|
} |
193 |
1
|
try { |
194 |
1
|
object7.getElementName(11); |
195 |
0
|
fail("getter should throw exception for access to non existent element"); |
196 |
|
} catch (RuntimeException e) { |
197 |
|
|
198 |
|
} |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
@link |
203 |
|
|
|
|
| 76.3% |
Uncovered Elements: 9 (38) |
Complexity: 10 |
Complexity Density: 0.26 |
1
PASS
|
|
204 |
1
|
public void testGetElementOccurrence() {... |
205 |
1
|
assertEquals(1, object1.getElementOccurrence(0)); |
206 |
1
|
assertEquals(1, object1.getElementOccurrence(1)); |
207 |
1
|
assertEquals(1, object1.getElementOccurrence(2)); |
208 |
1
|
try { |
209 |
1
|
object1.getElementOccurrence(3); |
210 |
0
|
fail("getter should throw exception for access to non existent element"); |
211 |
|
} catch (RuntimeException e) { |
212 |
|
|
213 |
|
} |
214 |
1
|
try { |
215 |
1
|
object1.getElementOccurrence(11); |
216 |
0
|
fail("getter should throw exception for access to non existent element"); |
217 |
|
} catch (RuntimeException e) { |
218 |
|
|
219 |
|
} |
220 |
1
|
try { |
221 |
1
|
object1.getElementOccurrence(-1); |
222 |
0
|
fail("getter should throw exception for access to non existent element"); |
223 |
|
} catch (RuntimeException e) { |
224 |
|
|
225 |
|
} |
226 |
1
|
assertEquals(1, object6.getElementOccurrence(0)); |
227 |
1
|
assertEquals(2, object6.getElementOccurrence(1)); |
228 |
1
|
assertEquals(1, object6.getElementOccurrence(2)); |
229 |
1
|
assertEquals(1, object6.getElementOccurrence(3)); |
230 |
1
|
try { |
231 |
1
|
object6.getElementOccurrence(4); |
232 |
0
|
fail("getter should throw exception for access to non existent element"); |
233 |
|
} catch (RuntimeException e) { |
234 |
|
|
235 |
|
} |
236 |
1
|
try { |
237 |
1
|
object6.getElementOccurrence(11); |
238 |
0
|
fail("getter should throw exception for access to non existent element"); |
239 |
|
} catch (RuntimeException e) { |
240 |
|
|
241 |
|
} |
242 |
1
|
try { |
243 |
1
|
object6.getElementOccurrence(-1); |
244 |
0
|
fail("getter should throw exception for access to non existent element"); |
245 |
|
} catch (RuntimeException e) { |
246 |
|
|
247 |
|
} |
248 |
1
|
assertEquals(1, object7.getElementOccurrence(0)); |
249 |
1
|
assertEquals(1, object7.getElementOccurrence(1)); |
250 |
1
|
assertEquals(1, object7.getElementOccurrence(2)); |
251 |
1
|
assertEquals(11, object7.getElementOccurrence(3)); |
252 |
1
|
try { |
253 |
1
|
object7.getElementOccurrence(4); |
254 |
0
|
fail("getter should throw exception for access to non existent element"); |
255 |
|
} catch (RuntimeException e) { |
256 |
|
|
257 |
|
} |
258 |
1
|
try { |
259 |
1
|
object7.getElementOccurrence(11); |
260 |
0
|
fail("getter should throw exception for access to non existent element"); |
261 |
|
} catch (RuntimeException e) { |
262 |
|
|
263 |
|
} |
264 |
1
|
try { |
265 |
1
|
object7.getElementOccurrence(-1); |
266 |
0
|
fail("getter should throw exception for access to non existent element"); |
267 |
|
} catch (RuntimeException e) { |
268 |
|
|
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
|
@link |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
275 |
1
|
public void testGetAttribute() {... |
276 |
1
|
assertNull(object1.getAttribute()); |
277 |
1
|
assertNull(object2.getAttribute()); |
278 |
1
|
assertNull(object3.getAttribute()); |
279 |
1
|
assertNull(object4.getAttribute()); |
280 |
1
|
assertEquals("education", object5.getAttribute()); |
281 |
1
|
assertNull(object6.getAttribute()); |
282 |
1
|
assertEquals("love", object7.getAttribute()); |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
@link |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
288 |
1
|
public void testToString() {... |
289 |
1
|
assertNotNull(object1.toString()); |
290 |
1
|
assertNotNull(object2.toString()); |
291 |
1
|
assertNotNull(object3.toString()); |
292 |
1
|
assertNotNull(object4.toString()); |
293 |
1
|
assertNotNull(object5.toString()); |
294 |
1
|
assertNotNull(object6.toString()); |
295 |
1
|
assertNotNull(object7.toString()); |
296 |
|
} |
297 |
|
|
298 |
|
|
299 |
|
@link |
300 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
1
PASS
|
|
301 |
1
|
public void testHashCode() {... |
302 |
1
|
assertTrue(object1.hashCode() != object2.hashCode()); |
303 |
1
|
assertTrue(object1.hashCode() == object3.hashCode()); |
304 |
1
|
assertTrue(object1.hashCode() != object4.hashCode()); |
305 |
1
|
assertTrue(object1.hashCode() != object5.hashCode()); |
306 |
1
|
assertTrue(object1.hashCode() != object6.hashCode()); |
307 |
1
|
assertTrue(object1.hashCode() != object7.hashCode()); |
308 |
1
|
assertTrue(object2.hashCode() != object3.hashCode()); |
309 |
1
|
assertTrue(object2.hashCode() != object4.hashCode()); |
310 |
1
|
assertTrue(object2.hashCode() != object5.hashCode()); |
311 |
1
|
assertTrue(object2.hashCode() != object6.hashCode()); |
312 |
1
|
assertTrue(object2.hashCode() != object7.hashCode()); |
313 |
1
|
assertTrue(object3.hashCode() != object4.hashCode()); |
314 |
1
|
assertTrue(object3.hashCode() != object5.hashCode()); |
315 |
1
|
assertTrue(object3.hashCode() != object6.hashCode()); |
316 |
1
|
assertTrue(object3.hashCode() != object7.hashCode()); |
317 |
1
|
assertTrue(object4.hashCode() != object5.hashCode()); |
318 |
1
|
assertTrue(object4.hashCode() != object6.hashCode()); |
319 |
1
|
assertTrue(object4.hashCode() != object7.hashCode()); |
320 |
1
|
assertTrue(object5.hashCode() != object6.hashCode()); |
321 |
1
|
assertTrue(object5.hashCode() != object7.hashCode()); |
322 |
1
|
assertTrue(object6.hashCode() != object7.hashCode()); |
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
@link |
327 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (57) |
Complexity: 1 |
Complexity Density: 0.02 |
1
PASS
|
|
328 |
1
|
public void testEquals() {... |
329 |
1
|
assertTrue(object1.equals(object1)); |
330 |
1
|
assertFalse(object1.equals(object2)); |
331 |
1
|
assertTrue(object1.equals(object3)); |
332 |
1
|
assertTrue(object1.hashCode() == object3.hashCode()); |
333 |
1
|
assertFalse(object1.equals(object4)); |
334 |
1
|
assertFalse(object1.equals(object5)); |
335 |
1
|
assertFalse(object1.equals(object6)); |
336 |
1
|
assertFalse(object1.equals(object7)); |
337 |
1
|
assertFalse(object2.equals(object1)); |
338 |
1
|
assertTrue(object2.equals(object2)); |
339 |
1
|
assertFalse(object2.equals(object3)); |
340 |
1
|
assertFalse(object2.equals(object4)); |
341 |
1
|
assertFalse(object2.equals(object5)); |
342 |
1
|
assertFalse(object2.equals(object6)); |
343 |
1
|
assertFalse(object2.equals(object7)); |
344 |
1
|
assertTrue(object3.equals(object1)); |
345 |
1
|
assertFalse(object3.equals(object2)); |
346 |
1
|
assertTrue(object3.equals(object3)); |
347 |
1
|
assertFalse(object3.equals(object4)); |
348 |
1
|
assertFalse(object3.equals(object5)); |
349 |
1
|
assertFalse(object3.equals(object6)); |
350 |
1
|
assertFalse(object3.equals(object7)); |
351 |
1
|
assertFalse(object4.equals(object1)); |
352 |
1
|
assertFalse(object4.equals(object2)); |
353 |
1
|
assertFalse(object4.equals(object3)); |
354 |
1
|
assertTrue(object4.equals(object4)); |
355 |
1
|
assertFalse(object4.equals(object5)); |
356 |
1
|
assertFalse(object4.equals(object6)); |
357 |
1
|
assertFalse(object4.equals(object7)); |
358 |
1
|
assertFalse(object5.equals(object1)); |
359 |
1
|
assertFalse(object5.equals(object2)); |
360 |
1
|
assertFalse(object5.equals(object3)); |
361 |
1
|
assertFalse(object5.equals(object4)); |
362 |
1
|
assertTrue(object5.equals(object5)); |
363 |
1
|
assertFalse(object5.equals(object6)); |
364 |
1
|
assertFalse(object5.equals(object7)); |
365 |
1
|
assertFalse(object6.equals(object1)); |
366 |
1
|
assertFalse(object6.equals(object2)); |
367 |
1
|
assertFalse(object6.equals(object3)); |
368 |
1
|
assertFalse(object6.equals(object4)); |
369 |
1
|
assertFalse(object6.equals(object5)); |
370 |
1
|
assertTrue(object6.equals(object6)); |
371 |
1
|
assertFalse(object6.equals(object7)); |
372 |
1
|
assertFalse(object6.equals(object1)); |
373 |
1
|
assertFalse(object6.equals(object2)); |
374 |
1
|
assertFalse(object6.equals(object3)); |
375 |
1
|
assertFalse(object6.equals(object4)); |
376 |
1
|
assertFalse(object6.equals(object5)); |
377 |
1
|
assertTrue(object6.equals(object6)); |
378 |
1
|
assertFalse(object6.equals(object7)); |
379 |
1
|
assertTrue(object7.equals(object7)); |
380 |
1
|
assertFalse((new SimpleXPath("/cat/on/the/hot@tin")).equals(new SimpleXPath("/cat/on/the/hot"))); |
381 |
1
|
assertFalse((new SimpleXPath("/cat[2]/on/the/hot@tin")).equals(new SimpleXPath("/cat/on/the/hot@tin"))); |
382 |
1
|
final SimpleXPath object10 = new SimpleXPath("/cat[1]/on/the/hot@tin"); |
383 |
1
|
final SimpleXPath object11 = new SimpleXPath("/cat/on/the/hot@tin"); |
384 |
1
|
assertTrue(object10.equals(object11)); |
385 |
1
|
assertTrue(object10.hashCode() == object11.hashCode()); |
386 |
|
} |
387 |
|
|
388 |
|
} |