Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
114   240   20   6.71
0   176   0.18   17
17     1.18  
1    
 
  SourceFileExceptionListTest       Line # 26 114 20 91.6% 0.9160305
 
  (10)
 
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.se.common;
17   
18    import org.qedeq.base.io.SourceArea;
19    import org.qedeq.base.test.QedeqTestCase;
20   
21    /**
22    * Test class.
23    *
24    * @author Michael Meyling
25    */
 
26    public class SourceFileExceptionListTest extends QedeqTestCase {
27   
28    private SourceFileExceptionList empty;
29   
30    private SourceFileExceptionList one;
31   
32    private SourceFileExceptionList two;
33   
34    private SourceFileExceptionList three;
35   
36    private SourceFileExceptionList four;
37   
38    private final Plugin plugin = new Plugin(){
 
39  0 toggle public String getServiceDescription() {
40  0 return "i am doing nothing";
41    }
42   
 
43  0 toggle public String getServiceId() {
44  0 return this.getClass().toString();
45    }
46   
 
47  0 toggle public String getServiceAction() {
48  0 return "dummy";
49    }
50    };
51   
 
52  0 toggle public SourceFileExceptionListTest(){
53  0 super();
54    }
55   
 
56  10 toggle public SourceFileExceptionListTest(final String name){
57  10 super(name);
58    }
59   
 
60  10 toggle protected void setUp() throws Exception {
61  10 super.setUp();
62  10 empty = new SourceFileExceptionList();
63  10 final SourceFileException oneEx = new SourceFileException(plugin, 4711,
64    "no big problem", new RuntimeException("something bad"), (SourceArea) null, (SourceArea) null);
65  10 one = new SourceFileExceptionList(oneEx);
66  10 one.add(oneEx);
67  10 two = new SourceFileExceptionList(one);
68  10 two.add(new SourceFileException(plugin, 815,
69    "no big problem", new RuntimeException("something else"), (SourceArea) null, (SourceArea) null));
70  10 three = new SourceFileExceptionList();
71  10 three.add(two);
72  10 three.add(two);
73  10 three.add(new SourceFileException(plugin, 17234,
74    "no big problem", new RuntimeException("something other"), (SourceArea) null, (SourceArea) null));
75  10 four = new SourceFileExceptionList(two);
76  10 four.add(new SourceFileException(plugin, 815,
77    "big problem", new RuntimeException("something else"), (SourceArea) null, (SourceArea) null));
78    }
79   
 
80  10 toggle protected void tearDown() throws Exception {
81  10 empty = null;
82  10 one = null;
83  10 two = null;
84  10 three = null;
85  10 four = null;
86  10 super.tearDown();
87    }
88   
 
89  1 toggle public void testContructor() {
90  1 assertEquals(0, empty.size());
91  1 SourceFileExceptionList sf1 = new SourceFileExceptionList((SourceFileException) null);
92  1 assertEquals(0, sf1.size());
93  1 sf1.clear();
94  1 assertEquals(0, sf1.size());
95  1 SourceFileExceptionList sf2 = new SourceFileExceptionList((SourceFileExceptionList) null);
96  1 assertEquals(0, sf1.size());
97  1 sf2.clear();
98  1 assertEquals(0, sf2.size());
99    }
100   
101   
 
102  1 toggle public void testClear() {
103  1 assertEquals(1, one.size());
104  1 one.clear();
105  1 assertEquals(0, one.size());
106  1 assertEquals(3, three.size());
107  1 three.clear();
108  1 assertEquals(0, three.size());
109    }
110   
 
111  1 toggle public void testAdd1() {
112  1 assertEquals(1, one.size());
113  1 one.add((SourceFileException) null);
114  1 assertEquals(1, one.size());
115  1 one.add(new SourceFileException(plugin, 4711,
116    "no big problem", new RuntimeException("something bad"), (SourceArea) null, (SourceArea) null));
117  1 assertEquals(1, one.size());
118  1 one.add(new SourceFileException(plugin, 4711,
119    "no big problem", new RuntimeException("something bad2"), (SourceArea) null, (SourceArea) null));
120  1 assertEquals(2, one.size());
121    }
122   
 
123  1 toggle public void testAdd2() {
124  1 assertEquals(1, one.size());
125  1 one.add((SourceFileExceptionList) null);
126  1 assertEquals(1, one.size());
127  1 one.add(one);
128  1 assertEquals(1, one.size());
129  1 one.add(two);
130  1 assertEquals(2, one.size());
131  1 three.add(new SourceFileException(plugin, 4711,
132    "no big problem", new RuntimeException("something bad2"), (SourceArea) null, (SourceArea) null));
133  1 one.add(three);
134  1 assertEquals(4, one.size());
135    }
136   
137    /**
138    * Test size.
139    */
 
140  1 toggle public void testSize() {
141  1 assertEquals(0, empty.size());
142  1 assertEquals(1, one.size());
143  1 assertEquals(2, two.size());
144  1 assertEquals(3, three.size());
145  1 assertEquals(3, four.size());
146    }
147   
148    /**
149    * Test equals.
150    */
 
151  1 toggle public void testEquals() {
152  1 assertEquals(empty, empty);
153  1 assertEquals(one, one);
154  1 assertEquals(two, two);
155  1 assertEquals(three, three);
156  1 assertFalse(empty.equals(null));
157  1 assertFalse(empty.equals(empty.toString()));
158  1 assertFalse(empty.equals(one));
159  1 assertFalse(empty.equals(two));
160  1 assertFalse(empty.equals(three));
161  1 assertFalse(one.equals(null));
162  1 assertFalse(one.equals(one.toString()));
163  1 assertFalse(one.equals(empty));
164  1 assertFalse(one.equals(two));
165  1 assertFalse(one.equals(three));
166  1 assertFalse(two.equals(null));
167  1 assertFalse(two.equals(two.toString()));
168  1 assertFalse(two.equals(one));
169  1 assertFalse(two.equals(empty));
170  1 assertFalse(two.equals(three));
171  1 assertFalse(three.equals(null));
172  1 assertFalse(three.equals(three.toString()));
173  1 assertFalse(three.equals(one));
174  1 assertFalse(three.equals(empty));
175  1 assertFalse(three.equals(one));
176  1 assertFalse(three.equals(four));
177  1 assertFalse(four.equals(three));
178    }
179   
 
180  1 toggle public void testHashCode() {
181  1 assertFalse(empty.hashCode() == one.hashCode());
182  1 assertFalse(one.hashCode() == two.hashCode());
183  1 assertFalse(two.hashCode() == three.hashCode());
184    }
185   
186    /**
187    * Test get.
188    */
 
189  1 toggle public void testGet() {
190  1 try {
191  1 empty.get(0);
192  0 fail("wrong index exception expected");
193    } catch (Exception e) {
194    // ok
195    }
196  1 try {
197  1 three.get(3);
198  0 fail("wrong index exception expected");
199    } catch (Exception e) {
200    // ok
201    }
202  1 try {
203  1 two.get(-1);
204  0 fail("wrong index exception expected");
205    } catch (Exception e) {
206    // ok
207    }
208  1 assertEquals(4711, one.get(0).getErrorCode());
209  1 assertEquals(4711, two.get(0).getErrorCode());
210  1 assertEquals(815, two.get(1).getErrorCode());
211  1 assertEquals(4711, three.get(0).getErrorCode());
212  1 assertEquals(815, three.get(1).getErrorCode());
213  1 assertEquals(17234, three.get(2).getErrorCode());
214  1 assertEquals(17234, three.toArray()[2].getErrorCode());
215    }
216   
217    /**
218    * Test getCause.
219    */
 
220  1 toggle public void testGetCause() {
221  1 assertTrue(one.getCause() instanceof SourceFileException);
222  1 SourceFileException e = (SourceFileException) one.getCause();
223  1 assertEquals(4711, e.getErrorCode());
224  1 e = (SourceFileException) two.getCause();
225  1 assertEquals(4711, e.getErrorCode());
226  1 e = (SourceFileException) three.getCause();
227  1 assertEquals(4711, e.getErrorCode());
228    }
229   
230    /**
231    * Test getCause.
232    */
 
233  1 toggle public void testToString() {
234  1 assertEquals(three.toString(), "org.qedeq.kernel.se.common.SourceFileExceptionList\n"
235    + "0: \t4711: no big problem; something bad\n"
236    + "1: \t815: no big problem; something else\n"
237    + "2: \t17234: no big problem; something other");
238    }
239   
240    }