Clover coverage report - PMD - 3.3
Coverage timestamp: Thu Sep 15 2005 17:59:57 EDT
file stats: LOC: 45   Methods: 2
NCLOC: 35   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TestClassWithoutTestCases.java 83.3% 93.8% 100% 90%
coverage coverage
 1    /**
 2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 3    */
 4    package net.sourceforge.pmd.rules.junit;
 5   
 6    import net.sourceforge.pmd.AbstractRule;
 7    import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration;
 8    import net.sourceforge.pmd.ast.ASTMethodDeclarator;
 9   
 10    import java.util.Iterator;
 11    import java.util.List;
 12   
 13    public class TestClassWithoutTestCases extends AbstractRule {
 14   
 15  4 public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
 16  4 if (node.isInterface() || node.isNested()) {
 17  0 return data;
 18    }
 19   
 20  4 String className = node.getImage();
 21  4 if (className.endsWith("Test")) {
 22  3 List m = node.findChildrenOfType(ASTMethodDeclarator.class);
 23  3 boolean testsFound = false;
 24  3 if (m!=null) {
 25  3 for (Iterator it = m.iterator() ; it.hasNext() && !testsFound ; ) {
 26  2 ASTMethodDeclarator md = (ASTMethodDeclarator) it.next();
 27  2 if (!isInInnerClassOrInterface(md)
 28    && md.getImage().startsWith("test")) {
 29  1 testsFound = true;
 30    }
 31    }
 32    }
 33   
 34  3 if (!testsFound) {
 35  2 addViolation(data, node);
 36    }
 37   
 38    }
 39  4 return data;
 40    }
 41  2 private boolean isInInnerClassOrInterface(ASTMethodDeclarator md) {
 42  2 ASTClassOrInterfaceDeclaration p = (ASTClassOrInterfaceDeclaration)md.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
 43  2 return p != null && p.isNested();
 44    }
 45    }