Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
107   197   14   13.38
0   150   0.13   8
8     1.75  
1    
 
  ModuleContextTest       Line # 26 107 14 93% 0.93043476
 
  (5)
 
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.SourcePosition;
19    import org.qedeq.base.test.QedeqTestCase;
20   
21    /**
22    * Test class.
23    *
24    * @author Michael Meyling
25    */
 
26    public class ModuleContextTest extends QedeqTestCase {
27   
28    private ModuleContext con1;
29    private ModuleContext con2;
30    private ModuleContext con3;
31    private ModuleContext con4;
32    private ModuleContext con5;
33    private ModuleContext con6;
34    private ModuleContext con10;
35    private ModuleContext con11;
36   
 
37  0 toggle public ModuleContextTest(){
38  0 super();
39    }
40   
 
41  5 toggle public ModuleContextTest(final String name){
42  5 super(name);
43    }
44   
 
45  5 toggle public void setUp() throws Exception {
46  5 super.setUp();
47  5 this.con1 = new ModuleContext(DefaultModuleAddress.MEMORY);
48  5 this.con2 = new ModuleContext(new DefaultModuleAddress(true, "bee"));
49  5 this.con3 = new ModuleContext(DefaultModuleAddress.MEMORY, "location!location!");
50  5 this.con4 = new ModuleContext(new DefaultModuleAddress(true, "bee"), "location!location!");
51  5 this.con5 = new ModuleContext(DefaultModuleAddress.MEMORY, "");
52  5 this.con6 = new ModuleContext(new DefaultModuleAddress(true, "bee"), "location!location");
53  5 this.con10 = new ModuleContext(DefaultModuleAddress.MEMORY, "",
54    new SourcePosition(1, 1),
55    new SourcePosition(1, 2));
56  5 this.con11 = new ModuleContext(con10, "anotherLocation");
57    }
58   
59    /**
60    * Test constructor.
61    */
 
62  1 toggle public void testConstructor() throws Exception {
63  1 assertEquals(DefaultModuleAddress.MEMORY, con1.getModuleLocation());
64  1 assertEquals("", con1.getLocationWithinModule());
65  1 assertEquals(new DefaultModuleAddress(true, "bee"), con2.getModuleLocation());
66  1 assertEquals("", con2.getLocationWithinModule());
67  1 assertEquals(DefaultModuleAddress.MEMORY, con3.getModuleLocation());
68  1 assertEquals("location!location!", con3.getLocationWithinModule());
69  1 assertEquals(new DefaultModuleAddress(true, "bee"), con4.getModuleLocation());
70  1 assertEquals("location!location!", con4.getLocationWithinModule());
71  1 assertEquals(con1, new ModuleContext(con1));
72  1 assertEquals(con6, new ModuleContext(con6));
73  1 assertEquals("anotherLocation", con11.getLocationWithinModule());
74  1 ModuleContext con51 = new ModuleContext(con5);
75  1 assertEquals(con51, con5);
76  1 con5.setLocationWithinModule("another location");
77  1 assertFalse(con51.equals(con5));
78  1 try {
79  1 new ModuleContext((ModuleAddress) null);
80  0 fail("Exception expected");
81    } catch (Exception e) {
82    // ok
83    }
84  1 try {
85  1 new ModuleContext((ModuleContext) null);
86  0 fail("Exception expected");
87    } catch (Exception e) {
88    // ok
89    }
90  1 try {
91  1 new ModuleContext((ModuleContext) null, null);
92  0 fail("Exception expected");
93    } catch (Exception e) {
94    // ok
95    }
96  1 try {
97  1 new ModuleContext((ModuleAddress) null, null);
98  0 fail("Exception expected");
99    } catch (Exception e) {
100    // ok
101    }
102  1 try {
103  1 new ModuleContext(this.con1, null);
104  0 fail("Exception expected");
105    } catch (Exception e) {
106    // ok
107    }
108  1 try {
109  1 new ModuleContext(this.con1.getModuleLocation(), null);
110  0 fail("Exception expected");
111    } catch (Exception e) {
112    // ok
113    }
114    }
115   
116    /**
117    * Test constructor.
118    */
 
119  1 toggle public void testGetDelta() throws Exception {
120  1 assertNull(con1.getStartDelta());
121  1 assertNull(con6.getStartDelta());
122  1 assertNull(con1.getEndDelta());
123  1 assertNull(con5.getEndDelta());
124  1 assertEquals(new SourcePosition(1, 1), con10.getStartDelta());
125  1 assertEquals(new SourcePosition(1, 2), con10.getEndDelta());
126    }
127   
128    /**
129    * Test hash code generation.
130    */
 
131  1 toggle public void testHashCode() throws Exception {
132  1 assertFalse(con1.hashCode() == con2.hashCode());
133  1 assertFalse(con1.hashCode() == con3.hashCode());
134  1 assertFalse(con1.hashCode() == con4.hashCode());
135  1 assertEquals(con1.hashCode(), con5.hashCode());
136  1 assertFalse(con1.hashCode() == con6.hashCode());
137  1 assertFalse(con1.hashCode() == con10.hashCode());
138  1 assertFalse(con2.hashCode() == con3.hashCode());
139  1 assertFalse(con2.hashCode() == con4.hashCode());
140  1 assertFalse(con2.hashCode() == con5.hashCode());
141  1 assertFalse(con2.hashCode() == con6.hashCode());
142  1 assertFalse(con2.hashCode() == con10.hashCode());
143  1 assertFalse(con3.hashCode() == con4.hashCode());
144  1 assertFalse(con3.hashCode() == con5.hashCode());
145  1 assertFalse(con3.hashCode() == con6.hashCode());
146  1 assertFalse(con3.hashCode() == con10.hashCode());
147  1 assertFalse(con4.hashCode() == con5.hashCode());
148  1 assertFalse(con4.hashCode() == con6.hashCode());
149  1 assertFalse(con4.hashCode() == con10.hashCode());
150  1 assertFalse(con5.hashCode() == con6.hashCode());
151  1 assertFalse(con5.hashCode() == con10.hashCode());
152  1 assertFalse(con6.hashCode() == con10.hashCode());
153    }
154   
 
155  1 toggle public void testEqualsObject() throws Exception {
156  1 assertEquals(con1, con1);
157  1 assertEquals(con2, con2);
158  1 assertEquals(con3, con3);
159  1 assertEquals(con4, con4);
160  1 assertEquals(con5, con5);
161  1 assertEquals(con6, con6);
162  1 assertEquals(con10, con10);
163  1 assertFalse(con1.equals(null));
164  1 assertFalse(con1.equals(con1.toString()));
165  1 assertFalse(con2.equals(null));
166  1 assertFalse(con2.equals(con2.toString()));
167  1 assertFalse(con11.equals(null));
168  1 assertFalse(con11.equals(con11.toString()));
169  1 assertFalse(con1.equals(con2));
170  1 assertFalse(con1.equals(con3));
171  1 assertFalse(con1.equals(con4));
172  1 assertEquals(con1, con5);
173  1 assertFalse(con1.equals(con6));
174  1 assertFalse(con2.equals(con3));
175  1 assertFalse(con2.equals(con4));
176  1 assertFalse(con2.equals(con5));
177  1 assertFalse(con2.equals(con6));
178  1 assertFalse(con3.equals(con4));
179  1 assertFalse(con3.equals(con5));
180  1 assertFalse(con3.equals(con6));
181  1 assertFalse(con4.equals(con5));
182  1 assertFalse(con4.equals(con6));
183  1 assertFalse(con5.equals(con6));
184    }
185   
 
186  1 toggle public void testToString() {
187  1 assertEquals("memory://default::null:null", con1.toString());
188  1 assertEquals("memory://bee::null:null", con2.toString());
189  1 assertEquals("memory://default:location!location!:null:null", con3.toString());
190  1 assertEquals("memory://bee:location!location!:null:null", con4.toString());
191  1 assertEquals("memory://default::null:null", con5.toString());
192  1 assertEquals("memory://bee:location!location:null:null", con6.toString());
193  1 assertEquals("memory://default::1:1:1:2", con10.toString());
194  1 assertEquals("memory://default:anotherLocation:null:null", con11.toString());
195    }
196   
197    }