Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
210   388   35   21
0   291   0.17   10
10     3.5  
1    
 
  SimpleXPathTest       Line # 26 210 35 88.6% 0.8863636
 
  (8)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.xml.tracker;
17   
18    import org.qedeq.base.test.QedeqTestCase;
19   
20    /**
21    * Test {@link org.qedeq.kernel.xml.tracker.SimpleXPath}.
22    *
23    * @version $Revision: 1.1 $
24    * @author Michael Meyling
25    */
 
26    public class SimpleXPathTest extends QedeqTestCase {
27   
28    /** Test object. */
29    private SimpleXPath object1;
30   
31    /** Test object. */
32    private SimpleXPath object2;
33   
34    /** Test object. */
35    private SimpleXPath object3;
36   
37    /** Test object. */
38    private SimpleXPath object4;
39   
40    /** Test object. */
41    private SimpleXPath object5;
42   
43    /** Test object. */
44    private SimpleXPath object6;
45   
46    /** Test object. */
47    private SimpleXPath object7;
48   
 
49  8 toggle 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   
 
60  8 toggle 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    * Test constructor.
73    */
 
74  1 toggle public void testSimpleXPath() {
75  1 try {
76  1 new SimpleXPath("");
77  0 fail("empty XPath is forbidden");
78    } catch (RuntimeException e) {
79    // expected
80    }
81  1 try {
82  1 new SimpleXPath("no_absolute_path");
83  0 fail("relative path is forbidden");
84    } catch (RuntimeException e) {
85    // expected
86    }
87  1 try {
88  1 new SimpleXPath("no_absolute_path");
89  0 fail("relative path is forbidden");
90    } catch (RuntimeException e) {
91    // expected
92    }
93  1 try {
94  1 new SimpleXPath("/hello//again");
95  0 fail("empty element is forbidden");
96    } catch (RuntimeException e) {
97    // expected
98    }
99  1 try {
100  1 new SimpleXPath("/hello/again/@");
101  0 fail("empty attribute is forbidden");
102    } catch (RuntimeException e) {
103    // expected
104    }
105  1 try {
106  1 new SimpleXPath("/hello/again/");
107  0 fail("XPath should not end with /");
108    } catch (RuntimeException e) {
109    // expected
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    // expected
116    }
117    }
118   
119    /**
120    * Test {@link SimpleXPath#size()}.
121    */
 
122  1 toggle 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    * Test {@link SimpleXPath#getElementName(int)}.
132    */
 
133  1 toggle 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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
198    }
199    }
200   
201    /**
202    * Test {@link SimpleXPath#getElementOccurrence(int)}.
203    */
 
204  1 toggle 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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
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    // expected
269    }
270    }
271   
272    /**
273    * Test {@link SimpleXPath#getAttribute()}.
274    */
 
275  1 toggle 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    * Test {@link SimpleXPath#toString()}.
287    */
 
288  1 toggle 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    * Test {@link SimpleXPath#hashCode()}.
300    */
 
301  1 toggle 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    * Test {@link SimpleXPath#equals(Object)}.
327    */
 
328  1 toggle 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    }