1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
/*******************************************************************************
* Copyright (c) 2010 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.coverage.test.model;
import junit.framework.Assert;
import org.eclipse.osee.coverage.model.CoverageItem;
import org.eclipse.osee.coverage.model.CoverageOptionManager;
import org.eclipse.osee.coverage.model.CoverageUnit;
import org.eclipse.osee.coverage.model.SimpleCoverageUnitFileContentsProvider;
import org.eclipse.osee.coverage.test.util.CoverageTestUtil;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.junit.Before;
import org.junit.Test;
/**
* @author Donald G. Dunne
*/
public class CoverageUnitTest {
public static CoverageUnit cu = null, childCu = null;
public static CoverageItem ci1 = null;
public static SimpleCoverageUnitFileContentsProvider fileContentsProvider =
new SimpleCoverageUnitFileContentsProvider();
@Before
public void testSetup() throws OseeCoreException {
cu = new CoverageUnit(null, "Top CU", "C:/UserData/", fileContentsProvider);
cu.setOrderNumber("33");
ci1 = new CoverageItem(cu, CoverageOptionManager.Test_Unit, "1");
ci1.setName("this is text");
childCu = new CoverageUnit(cu, "Child Coverage Unit", "C:\\UserData\\", fileContentsProvider);
childCu.setOrderNumber("1");
CoverageItem item = new CoverageItem(childCu, CoverageOptionManager.Exception_Handling, "1");
childCu.addCoverageItem(item);
item = new CoverageItem(childCu, CoverageOptionManager.Test_Unit, "2");
childCu.addCoverageItem(item);
item = new CoverageItem(childCu, CoverageOptionManager.Not_Covered, "3");
childCu.addCoverageItem(item);
cu.addCoverageUnit(childCu);
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#CoverageUnit(org.eclipse.osee.coverage.model.ICoverage, java.lang.String, java.lang.String)}
* .
*/
@Test
public void testCoverageUnitICoverageStringString() {
Assert.assertNotNull(cu);
Assert.assertEquals("Top CU", cu.getName());
Assert.assertEquals("C:/UserData/", cu.getLocation());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#addCoverageItem(org.eclipse.osee.coverage.model.CoverageItem)}
* .
*/
@Test
public void testAddCoverageItem() {
Assert.assertEquals(1, cu.getCoverageItems().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageItem#getMethodNum()}.
*/
@Test
public void testSetGetOrderNum() {
cu.setOrderNumber("33");
Assert.assertEquals("33", cu.getOrderNumber());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#addCoverageUnit(org.eclipse.osee.coverage.model.CoverageUnit)}
* .
*/
@Test
public void testAddCoverageUnit() {
Assert.assertEquals(3, childCu.getChildren().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getChildren(boolean)}.
*/
@Test
public void testGetCoverageEditorItems() {
Assert.assertEquals(1, cu.getCoverageItems().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageUnits()}.
*/
@Test
public void testGetCoverageUnits() {
Assert.assertEquals(1, cu.getCoverageUnits().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageItems(boolean)}.
*/
@Test
public void testGetCoverageItemsBoolean() {
Assert.assertEquals(1, cu.getCoverageItems(false).size());
Assert.assertEquals(4, cu.getCoverageItems(true).size());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageItem(java.lang.String, java.lang.String)}.
*/
@Test
public void testGetCoverageItem() {
Assert.assertNotNull(cu.getCoverageItem("1", "1"));
Assert.assertNull(cu.getCoverageItem("1", "5"));
Assert.assertNull(cu.getCoverageItem("2", "1"));
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getName()}.
*/
@Test
public void testGetName() {
Assert.assertEquals("Child Coverage Unit", childCu.getName());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#setName(java.lang.String)}.
*/
@Test
public void testSetName() throws OseeCoreException {
String current = cu.getName();
cu.setName("New Name");
Assert.assertEquals("New Name", cu.getName());
cu.setName(current);
Assert.assertEquals(current, cu.getName());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getLocation()}.
*/
@Test
public void testSetGetLocation() {
String current = cu.getLocation();
cu.setLocation("New Loc");
Assert.assertEquals("New Loc", cu.getLocation());
cu.setLocation(current);
Assert.assertEquals(current, cu.getLocation());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getFileContents()}.
*/
@Test
public void testSetGetText() throws OseeCoreException {
String current = cu.getFileContents();
cu.setFileContents("New Text");
Assert.assertEquals("New Text", cu.getFileContents());
cu.setFileContents(current);
Assert.assertEquals(current, cu.getFileContents());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getGuid()}.
*/
@Test
public void testGetGuid() {
Assert.assertTrue(GUID.isValid(cu.getGuid()));
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getParentCoverageUnit()}.
*/
@Test
public void testGetParentCoverageUnit() {
Assert.assertNull(cu.getParentCoverageUnit());
Assert.assertEquals(cu, childCu.getParentCoverageUnit());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#isEditable()}.
*/
@Test
public void testIsEditable() {
Assert.assertTrue(cu.isEditable().isTrue());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageItemsCovered(boolean, org.eclipse.osee.coverage.model.CoverageOption[])}
* .
*/
@Test
public void testGetCoverageItemsCoveredBooleanCoverageOptionArray() {
Assert.assertEquals(1, cu.getCoverageItemsCovered(false, CoverageOptionManager.Test_Unit).size());
Assert.assertEquals(2, cu.getCoverageItemsCovered(true, CoverageOptionManager.Test_Unit).size());
Assert.assertEquals(1, cu.getCoverageItemsCovered(true, CoverageOptionManager.Not_Covered).size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#isCovered()}.
*/
@Test
public void testIsCovered() {
Assert.assertFalse(cu.isCovered());
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Test_Unit, true);
Assert.assertTrue(cu.isCovered());
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Not_Covered, true);
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getParent()}.
*/
@Test
public void testGetParent() {
Assert.assertNull(cu.getParent());
Assert.assertEquals(cu, childCu.getParent());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#setParentCoverageEditorItem(org.eclipse.osee.coverage.model.ICoverage)}
* .
*/
@Test
public void testSetParentCoverageEditorItem() {
Assert.assertEquals(cu, childCu.getParent());
childCu.setParent(null);
Assert.assertNull(childCu.getParent());
childCu.setParent(cu);
Assert.assertEquals(cu, childCu.getParent());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getNamespace()}.
*/
@Test
public void testSetGetNamespace() {
String current = cu.getNamespace();
cu.setNamespace("org.osee.coverageUnit");
Assert.assertEquals("org.osee.coverageUnit", cu.getNamespace());
cu.setNamespace(current);
Assert.assertEquals(current, cu.getNamespace());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getAssignees()}.
*/
@Test
public void testSetGetAssignees() {
String current = cu.getAssignees();
cu.setAssignees("New Assignees");
Assert.assertEquals("New Assignees", cu.getAssignees());
cu.setAssignees(current);
Assert.assertEquals(current, cu.getAssignees());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#isAssignable()}.
*/
@Test
public void testIsAssignable() {
Assert.assertTrue(cu.isEditable().isTrue());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getNotes()}.
*/
@Test
public void testSetGetNotes() {
String current = cu.getNotes();
cu.setNotes("New Notes");
Assert.assertEquals("New Notes", cu.getNotes());
cu.setNotes(current);
Assert.assertEquals(current, cu.getNotes());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageItemsCovered(boolean)}.
*/
@Test
public void testGetCoverageItemsCoveredBoolean() {
Assert.assertFalse(cu.isCovered());
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Test_Unit, true);
Assert.assertTrue(cu.isCovered());
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Not_Covered, true);
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getChildren()}.
*/
@Test
public void testGetChildrenItems() {
Assert.assertEquals(2, cu.getChildren().size());
Assert.assertEquals(3, childCu.getChildren().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoverageItems()}.
*/
@Test
public void testGetCoverageItems() {
Assert.assertEquals(1, cu.getCoverageItems().size());
Assert.assertEquals(3, childCu.getCoverageItems().size());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#updateAssigneesAndNotes(org.eclipse.osee.coverage.model.CoverageUnit)}
* .
*/
@Test
public void testUpdateAssigneesAndNotes() {
CoverageUnit cu2 = new CoverageUnit(null, "New Coverage Unit", "location", null);
cu2.setAssignees("assignees");
cu2.setNotes("notes");
Assert.assertNull(cu.getAssignees());
Assert.assertNull(cu.getNotes());
cu.updateAssigneesAndNotes(cu2);
Assert.assertEquals("assignees", cu.getAssignees());
Assert.assertEquals("notes", cu.getNotes());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#copy(boolean)}.
*/
@Test
public void testCopy() throws OseeCoreException {
CoverageUnit oldCu = new CoverageUnit(null, "This CU", "location", fileContentsProvider);
oldCu.setAssignees("assignees");
oldCu.setNotes("notes");
oldCu.setNamespace("namespace");
oldCu.setLocation("location");
CoverageUnit newCu = oldCu.copy(false);
Assert.assertEquals(oldCu.getGuid(), newCu.getGuid());
Assert.assertEquals(oldCu.getLocation(), newCu.getLocation());
Assert.assertEquals(oldCu.getName(), newCu.getName());
Assert.assertEquals(oldCu.getAssignees(), newCu.getAssignees());
Assert.assertEquals(oldCu.getNotes(), newCu.getNotes());
Assert.assertEquals(oldCu.getNamespace(), newCu.getNamespace());
Assert.assertEquals(oldCu.getFileContents(), newCu.getFileContents());
Assert.assertEquals(0, newCu.getCoverageItems().size());
newCu = childCu.copy(false);
Assert.assertEquals(0, newCu.getCoverageItems().size());
newCu = childCu.copy(true);
Assert.assertEquals(3, newCu.getCoverageItems().size());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#getCoveragePercent()}.
*/
@Test
public void testGetCoveragePercentAndStr() {
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Not_Covered, true);
Assert.assertFalse(cu.isCovered());
Assert.assertEquals(0.0, cu.getCoveragePercent());
Assert.assertEquals("0% - 0 / 4", cu.getCoveragePercentStr());
CoverageTestUtil.setAllCoverageMethod(cu, CoverageOptionManager.Test_Unit, true);
Assert.assertEquals(100.0, cu.getCoveragePercent());
Assert.assertEquals("100% - 4 / 4", cu.getCoveragePercentStr());
}
/**
* Test method for {@link org.eclipse.osee.coverage.model.CoverageUnit#isFolder()}.
*/
@Test
public void testSetIsFolder() {
boolean current = cu.isFolder();
Assert.assertFalse(cu.isFolder());
cu.setFolder(true);
Assert.assertTrue(cu.isFolder());
cu.setFolder(current);
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#removeCoverageItem(org.eclipse.osee.coverage.model.CoverageItem)}
* .
*/
@Test
public void testRemoveCoverageItem() {
Assert.assertEquals(1, cu.getCoverageItems().size());
cu.removeCoverageItem(ci1);
Assert.assertEquals(0, cu.getCoverageItems().size());
}
/**
* Test method for
* {@link org.eclipse.osee.coverage.model.CoverageUnit#removeCoverageUnit(org.eclipse.osee.coverage.model.CoverageUnit)}
* .
*/
@Test
public void testRemoveCoverageUnit() {
Assert.assertEquals(1, cu.getCoverageUnits().size());
cu.removeCoverageUnit(childCu);
Assert.assertEquals(0, cu.getCoverageUnits().size());
}
}
|