fixes #1453 Test Class Without Test Cases gives false positive
This commit is contained in:
@ -82,11 +82,13 @@ public abstract class AbstractJUnitRule extends AbstractJavaRule {
|
||||
return false; // skip various inapplicable method variations
|
||||
}
|
||||
|
||||
boolean result = false;
|
||||
if (isJUnit3Class) {
|
||||
return isJUnit3Method(method);
|
||||
} else {
|
||||
return isJUnit4Method(method);
|
||||
result = isJUnit3Method(method);
|
||||
}
|
||||
|
||||
result |= isJUnit4Method(method);
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isJUnit4Method(ASTMethodDeclaration method) {
|
||||
|
@ -3,7 +3,6 @@
|
||||
*/
|
||||
package net.sourceforge.pmd.lang.java.rule.junit;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
@ -21,17 +20,15 @@ public class TestClassWithoutTestCasesRule extends AbstractJUnitRule {
|
||||
boolean testsFound = false;
|
||||
|
||||
if (m != null) {
|
||||
for (Iterator<ASTMethodDeclaration> it = m.iterator(); it.hasNext() && !testsFound;) {
|
||||
ASTMethodDeclaration md = it.next();
|
||||
if (!isInInnerClassOrInterface(md)
|
||||
&& isJUnitMethod(md, data)) {
|
||||
testsFound = true;
|
||||
}
|
||||
for (ASTMethodDeclaration md : m) {
|
||||
if (!isInInnerClassOrInterface(md) && isJUnitMethod(md, data)) {
|
||||
testsFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!testsFound) {
|
||||
addViolation(data, node);
|
||||
addViolation(data, node);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -96,6 +96,23 @@ failure case does not extend TestCase
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class FooTest {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#1453 False positive when the test class extends an other.</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MyTest extends YourTest {
|
||||
|
||||
@Test
|
||||
public void falseMethod() {
|
||||
assertFalse(0 == 1);
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
Reference in New Issue
Block a user