Merge branch 'bug-1373' into pmd/5.4.x
This commit is contained in:
@ -11,6 +11,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTExtendsList;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTResultType;
|
||||
@ -59,12 +60,22 @@ public abstract class AbstractJUnitRule extends AbstractJavaRule {
|
||||
isJUnit4Class = isJUnit4Class(node);
|
||||
}
|
||||
|
||||
if (isJUnit3Class || isJUnit4Class) {
|
||||
if (!isTestNgClass(node) && (isJUnit3Class || isJUnit4Class)) {
|
||||
return super.visit(node, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private boolean isTestNgClass(ASTCompilationUnit node) {
|
||||
List<ASTImportDeclaration> imports = node.findDescendantsOfType(ASTImportDeclaration.class);
|
||||
for (ASTImportDeclaration i : imports) {
|
||||
if (i.getImportedName() != null && i.getImportedName().startsWith("org.testng")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isJUnitMethod(ASTMethodDeclaration method, Object data) {
|
||||
|
||||
if (!method.isPublic() || method.isAbstract() || method.isNative() || method.isStatic()) {
|
||||
|
@ -399,6 +399,27 @@ public class TestClass extends Assert {
|
||||
assertNull(null);
|
||||
assertThat("", containsString(""));
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1373 JUnitAssertionsShouldIncludeMessage is no longer compatible with TestNG</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class TestNgTestCase {
|
||||
@Test
|
||||
public void testAssert() {
|
||||
assertEquals("a", "b", "message");
|
||||
assertEquals(1, 2, "message");
|
||||
assertFalse(true, "message");
|
||||
assertTrue(false, "message");
|
||||
assertNotEquals(new Object(), new Object(), "message");
|
||||
assertNotNull(null, "message");
|
||||
assertNull(null, "message");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -28,6 +28,8 @@
|
||||
* [#1440](https://sourceforge.net/p/pmd/bugs/1440/): NPE in AvoidCallingFinalize
|
||||
* java-imports/UnnecessaryFullyQualifiedName
|
||||
* [#1436](https://sourceforge.net/p/pmd/bugs/1436/): UnnecessaryFullyQualifiedName false positive on clashing static imports with enums
|
||||
* java-junit/JUnitAssertionsShouldIncludeMessage
|
||||
* [#1373](https://sourceforge.net/p/pmd/bugs/1373/): JUnitAssertionsShouldIncludeMessage is no longer compatible with TestNG
|
||||
* java-migrating/JUnit4TestShouldUseBeforeAnnotation
|
||||
* [#1446](https://sourceforge.net/p/pmd/bugs/1446/): False positive with JUnit4TestShouldUseBeforeAnnotation when TestNG is used
|
||||
* java-naming/SuspiciousEqualsMethodName
|
||||
|
Reference in New Issue
Block a user