testIfEveryClassIsTested: the following classes have no test classes: {"org.qedeq.k...
testIfEveryClassIsTested: the following classes have no test classes: {"org.qedeq.k...
Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
26   109   15   8.67
14   56   0.58   3
3     5  
1    
 
  EachClassHasATestCase       Line # 32 26 15 79.1% 0.7906977
 
  (4)
 
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.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    * Basis class for all tests that check test class existence.
29    *
30    * @author Michael Meyling
31    */
 
32    public abstract class EachClassHasATestCase extends TestCase {
33   
34   
35    /**
36    * Constructor.
37    *
38    * @param name Test case name.
39    */
 
40  0 toggle public EachClassHasATestCase(final String name) {
41  0 super(name);
42    }
43   
44    /**
45    * Constructor.
46    */
 
47  4 toggle public EachClassHasATestCase() {
48  4 super();
49    }
50   
51    /**
52    * Get package name for those classes and the classes of their sub packages where we
53    * want test for tests.
54    *
55    * @return Tests for all classes of this package or its sub packages must occur.
56    */
57    public abstract String getPackagePrefix();
58   
59    /**
60    * Test if all classes have a test class.
61    */
 
62  4 toggle public void testIfEveryClassIsTested() {
63  4 String prefix = getPackagePrefix();
64  4 if (!prefix.endsWith(".")) {
65  4 prefix += ".";
66    }
67  4 final ClassFinder finder = new ClassFinder();
68  4 final Set allMatchingClassesInPath
69    = finder.findSubclasses(Object.class.getName(), prefix);
70  4 final Iterator i = allMatchingClassesInPath.iterator();
71  4 final Set classesToTest = new TreeSet(ClassFinder.CLASS_COMPARATOR);
72  4 final Set testClasses = new TreeSet(ClassFinder.CLASS_COMPARATOR);
73  1345 while (i.hasNext()) {
74  1341 Class c = (Class) i.next();
75  1341 if (c.getName().indexOf("$") < 0 && !Modifier.isInterface(c.getModifiers())
76    && c.getName().indexOf(".test.") < 0
77    && !c.getName().endsWith("TestSuite")) {
78  468 if (c.getName().endsWith("Test")) {
79    // System.out.println("adding test class " + c);
80  163 testClasses.add(c.getName());
81    } else {
82    // System.out.println(c + " " + finder.getLocationOf(c));
83  305 classesToTest.add(c);
84    }
85   
86   
87    }
88    }
89  4 final Set result = new TreeSet(ClassFinder.CLASS_COMPARATOR);
90  4 final Iterator j = classesToTest.iterator();
91  309 while (j.hasNext()) {
92  305 Class c = (Class) j.next();
93  133 if (!testClasses.contains(c.getName() + "Test") && !c.getName().endsWith("TestCase")
94    && !c.getName().endsWith("Tester")) {
95    // System.out.println("missing test for " + c.getName() + " mod: " +c.getModifiers());
96  0 result.add(c.getName());
97    } else {
98    // System.out.println("no need to test " + c.getName() + " mod: " +c.getModifiers());
99    }
100    }
101  2 if (!result.isEmpty()) {
102  0 System.out.println("The following classes have no test classes:");
103  0 System.out.println(StringUtility.asLines(result));
104  0 Test failure here fail("the following classes have no test classes: "
105    + StringUtility.toString(result));
106    }
107    }
108   
109    }