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