Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
90   212   18   5.29
0   160   0.2   17
17     1.06  
1    
 
  SourceFileExceptionTest       Line # 27 90 18 91.6% 0.91588783
 
  (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.io.SourcePosition;
20    import org.qedeq.base.test.QedeqTestCase;
21   
22    /**
23    * Test class.
24    *
25    * @author Michael Meyling
26    */
 
27    public class SourceFileExceptionTest extends QedeqTestCase {
28   
29    private SourceFileException one;
30    private SourceFileException two;
31    private SourceFileException three;
32    private SourceFileException four;
33    private SourceFileException five;
34    private SourceFileException six;
35    private SourceFileException seven;
36   
37    private final Plugin plugin = new Plugin(){
 
38  0 toggle public String getServiceDescription() {
39  0 return "i am doing nothing";
40    }
41   
 
42  0 toggle public String getServiceId() {
43  0 return this.getClass().toString();
44    }
45   
 
46  0 toggle public String getServiceAction() {
47  0 return "dummy";
48    }
49    };
50   
 
51  0 toggle public SourceFileExceptionTest(){
52  0 super();
53    }
54   
 
55  10 toggle public SourceFileExceptionTest(final String name){
56  10 super(name);
57    }
58   
 
59  10 toggle protected void setUp() throws Exception {
60  10 super.setUp();
61  10 one = new SourceFileException(plugin, 4711,
62    "no big problem", new RuntimeException("something bad"), (SourceArea) null,
63    (SourceArea) null);
64  10 two = new SourceFileException(plugin, 815,
65    "no big problem", new RuntimeException("something else"), new SourceArea("test"),
66    new SourceArea("toast"));
67  10 three = new SourceFileException(plugin, 17234,
68    "no big problem", new RuntimeException("something other"),
69    new SourceArea("test", new SourcePosition(1, 2), new SourcePosition(3, 17)),
70    new SourceArea("toast", new SourcePosition(13, 7), new SourcePosition(14, 19)));
71  10 four = new SourceFileException(plugin, 17234,
72    "no big problem", null,
73    new SourceArea("test", new SourcePosition(1, 2), new SourcePosition(3, 17)),
74    new SourceArea("toast", new SourcePosition(13, 7), new SourcePosition(14, 19)));
75  10 five = new SourceFileException(plugin, 17234,
76    "one big problem", null,
77    new SourceArea("test", SourcePosition.BEGIN, new SourcePosition(3, 17)),
78    new SourceArea("toast", new SourcePosition(13, 7), SourcePosition.BEGIN));
79  10 six = new SourceFileException(plugin,
80    new IllegalModuleDataException(107, "I am a bug!", new ModuleContext(
81    new DefaultModuleAddress()), new ModuleContext(new DefaultModuleAddress(true, "bee")),
82    new RuntimeException("I am the next reason.")), null, null);
83  10 seven = new SourceFileException(null, 17234,
84    "no big problem", new RuntimeException("no big problem"),
85    new SourceArea("test", new SourcePosition(1, 2), new SourcePosition(3, 17)),
86    new SourceArea("toast", new SourcePosition(13, 7), new SourcePosition(14, 19)));
87    }
88   
 
89  10 toggle protected void tearDown() throws Exception {
90  10 one = null;
91  10 two = null;
92  10 three = null;
93  10 four = null;
94  10 five = null;
95  10 six = null;
96  10 seven = null;
97  10 super.tearDown();
98    }
99   
100    /**
101    * Test constructor.
102    */
 
103  1 toggle public void testConstructor() {
104  1 assertEquals("no big problem; something bad", one.getMessage());
105  1 assertEquals(4711, one.getErrorCode());
106  1 assertNull(four.getCause());
107  1 assertEquals(1, three.getSourceArea().getStartPosition().getRow());
108  1 assertEquals(19, three.getReferenceArea().getEndPosition().getColumn());
109  1 try {
110  1 new SourceFileException(null, null, null, null);
111  0 fail("Exception expected");
112    } catch (Exception e) {
113    // ok
114    }
115  1 assertEquals(107, six.getErrorCode());
116    }
117   
 
118  1 toggle public void testGetMessage() {
119  1 assertEquals("no big problem; something else", two.getMessage());
120  1 assertEquals("no big problem", four.getMessage());
121  1 assertEquals("no big problem", seven.getMessage());
122    }
123   
 
124  1 toggle public void testGetCause() {
125  1 assertEquals("something bad", one.getCause().getMessage());
126    }
127   
 
128  1 toggle public void testToString() {
129  1 assertEquals("\t4711: no big problem; something bad", one.toString());
130  1 assertEquals("test:1:2:3:17\n\t17234: no big problem; something other", three.toString());
131    }
132   
 
133  1 toggle public void testGetDescription() {
134  1 assertEquals("\t4711: no big problem; something bad", one.getDescription());
135  1 assertEquals("test:1:2:3:17\n\t17234: no big problem; something other", three.getDescription());
136  1 assertEquals("test:1:2:3:17\n\t17234: no big problem", four.getDescription());
137    }
138   
 
139  1 toggle public void testGetPlugin() {
140  1 assertEquals(plugin, one.getService());
141  1 assertNull(seven.getService());
142    }
143   
 
144  1 toggle public void testGetSourceArea() {
145  1 assertEquals(null, one.getSourceArea());
146  1 assertEquals(new SourceArea("test"), two.getSourceArea());
147    }
148   
 
149  1 toggle public void testGetRefrenceArea() {
150  1 assertEquals(null, one.getReferenceArea());
151  1 assertEquals(new SourceArea("toast"), two.getReferenceArea());
152    }
153   
154    /**
155    * Test hash code generation.
156    */
 
157  1 toggle public void testHashCode() {
158  1 assertFalse(one.hashCode() == two.hashCode());
159  1 assertFalse(three.hashCode() == two.hashCode());
160  1 assertFalse(three.hashCode() == four.hashCode());
161  1 assertFalse(five.hashCode() == four.hashCode());
162  1 assertFalse(six.hashCode() == five.hashCode());
163  1 assertFalse(six.hashCode() == seven.hashCode());
164  1 assertFalse(one.hashCode() == three.hashCode());
165  1 assertFalse(one.hashCode() == four.hashCode());
166  1 assertFalse(one.hashCode() == five.hashCode());
167  1 assertFalse(one.hashCode() == six.hashCode());
168  1 assertFalse(one.hashCode() == seven.hashCode());
169  1 assertFalse(two.hashCode() == four.hashCode());
170  1 assertFalse(two.hashCode() == five.hashCode());
171  1 assertFalse(two.hashCode() == six.hashCode());
172  1 assertFalse(two.hashCode() == seven.hashCode());
173  1 assertFalse(three.hashCode() == five.hashCode());
174  1 assertFalse(three.hashCode() == six.hashCode());
175  1 assertFalse(three.hashCode() == seven.hashCode());
176  1 assertFalse(four.hashCode() == five.hashCode());
177  1 assertFalse(four.hashCode() == six.hashCode());
178  1 assertFalse(four.hashCode() == seven.hashCode());
179  1 assertFalse(five.hashCode() == six.hashCode());
180  1 assertFalse(five.hashCode() == seven.hashCode());
181    }
182   
183    /**
184    * Test equals method.
185    */
 
186  1 toggle public void testEqualsObject() {
187  1 assertEquals(one, one);
188  1 assertEquals(two, two);
189  1 assertEquals(three, three);
190  1 assertEquals(four, four);
191  1 assertEquals(five, five);
192  1 assertFalse(one.equals(null));
193  1 assertFalse(one.equals(one.toString()));
194  1 assertFalse(one.equals(two));
195  1 assertFalse(one.equals(three));
196  1 assertFalse(one.equals(four));
197  1 assertFalse(one.equals(five));
198  1 assertFalse(two.equals(null));
199  1 assertFalse(two.equals(two.toString()));
200  1 assertFalse(two.equals(one));
201  1 assertFalse(two.equals(three));
202  1 assertFalse(two.equals(four));
203  1 assertFalse(two.equals(five));
204  1 assertFalse(three.equals(null));
205  1 assertFalse(three.equals(one));
206  1 assertFalse(three.equals(two));
207  1 assertFalse(three.equals(four));
208  1 assertFalse(three.equals(five));
209    }
210   
211   
212    }