Merge branch 'bug-1453' into pmd/5.3.x

This commit is contained in:
Andreas Dangel
2016-01-28 22:24:57 +01:00
4 changed files with 29 additions and 11 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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>

View File

@ -29,6 +29,8 @@
* [#1449](https://sourceforge.net/p/pmd/bugs/1449/): false positive when casting a variable to short
* java-design/AccessorClassGeneration:
* [#1452](https://sourceforge.net/p/pmd/bugs/1452/): ArrayIndexOutOfBoundsException with Annotations for AccessorClassGenerationRule
* java-junit/TestClassWithoutTestCases:
* [#1453](https://sourceforge.net/p/pmd/bugs/1453/): Test Class Without Test Cases gives false positive
* General
* [#1455](https://sourceforge.net/p/pmd/bugs/1455/): PMD doesn't handle Java 8 explicit receiver parameters