1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.base.test; |
17 |
|
|
18 |
|
import java.lang.reflect.Modifier; |
19 |
|
import java.util.Iterator; |
20 |
|
import java.util.Set; |
21 |
|
import java.util.TreeSet; |
22 |
|
|
23 |
|
import junit.framework.TestCase; |
24 |
|
|
25 |
|
import org.qedeq.base.utility.StringUtility; |
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
@author |
31 |
|
|
|
|
| 89.1% |
Uncovered Elements: 5 (46) |
Complexity: 16 |
Complexity Density: 0.59 |
|
32 |
|
public abstract class EachClassHasATestCase extends TestCase { |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@param |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
0
|
public EachClassHasATestCase(final String name) {... |
41 |
0
|
super(name); |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
4
|
public EachClassHasATestCase() {... |
48 |
4
|
super(); |
49 |
|
} |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@return |
56 |
|
|
57 |
|
protected abstract String getPackagePrefix(); |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@return |
64 |
|
|
65 |
|
protected abstract boolean failIfTestClassesAreMissing(); |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
|
|
|
| 92.7% |
Uncovered Elements: 3 (41) |
Complexity: 14 |
Complexity Density: 0.56 |
4
-
|
|
70 |
4
|
public void testIfEveryClassIsTested() {... |
71 |
4
|
String prefix = getPackagePrefix(); |
72 |
4
|
if (!prefix.endsWith(".")) { |
73 |
4
|
prefix += "."; |
74 |
|
} |
75 |
4
|
final ClassFinder finder = new ClassFinder(); |
76 |
4
|
final Set allMatchingClassesInPath |
77 |
|
= finder.findSubclasses(Object.class.getName(), prefix); |
78 |
4
|
final Iterator i = allMatchingClassesInPath.iterator(); |
79 |
4
|
final Set classesToTest = new TreeSet(ClassFinder.CLASS_COMPARATOR); |
80 |
4
|
final Set testClasses = new TreeSet(ClassFinder.CLASS_COMPARATOR); |
81 |
1356
|
while (i.hasNext()) { |
82 |
1352
|
Class c = (Class) i.next(); |
83 |
1352
|
if (c.getName().indexOf("$") < 0 && !Modifier.isInterface(c.getModifiers()) |
84 |
|
&& c.getName().indexOf(".test.") < 0 |
85 |
|
&& !c.getName().endsWith("TestSuite")) { |
86 |
470
|
if (c.getName().endsWith("Test")) { |
87 |
|
|
88 |
165
|
testClasses.add(c.getName()); |
89 |
|
} else { |
90 |
|
|
91 |
305
|
classesToTest.add(c); |
92 |
|
} |
93 |
|
|
94 |
|
|
95 |
|
} |
96 |
|
} |
97 |
4
|
final Set result = new TreeSet(ClassFinder.CLASS_COMPARATOR); |
98 |
4
|
final Iterator j = classesToTest.iterator(); |
99 |
309
|
while (j.hasNext()) { |
100 |
305
|
Class c = (Class) j.next(); |
101 |
305
|
if (!testClasses.contains(c.getName() + "Test") && !c.getName().endsWith("TestCase") |
102 |
|
&& !c.getName().endsWith("Tester")) { |
103 |
|
|
104 |
171
|
result.add(c.getName()); |
105 |
|
} else { |
106 |
|
|
107 |
|
} |
108 |
|
} |
109 |
4
|
if (!result.isEmpty()) { |
110 |
2
|
System.out.println("The following classes have no test classes:"); |
111 |
2
|
System.out.println(StringUtility.asLines(result)); |
112 |
2
|
if (failIfTestClassesAreMissing()) { |
113 |
0
|
fail("the following classes have no test classes: " |
114 |
|
+ StringUtility.toString(result)); |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
|
119 |
|
} |