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