Merge branch 'bug-1373'
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.ASTClassOrInterfaceType;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTExtendsList;
|
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.ASTMethodDeclaration;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
import net.sourceforge.pmd.lang.java.ast.ASTName;
|
||||||
import net.sourceforge.pmd.lang.java.ast.ASTResultType;
|
import net.sourceforge.pmd.lang.java.ast.ASTResultType;
|
||||||
@ -59,12 +60,22 @@ public abstract class AbstractJUnitRule extends AbstractJavaRule {
|
|||||||
isJUnit4Class = isJUnit4Class(node);
|
isJUnit4Class = isJUnit4Class(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isJUnit3Class || isJUnit4Class) {
|
if (!isTestNgClass(node) && (isJUnit3Class || isJUnit4Class)) {
|
||||||
return super.visit(node, data);
|
return super.visit(node, data);
|
||||||
}
|
}
|
||||||
return 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) {
|
public boolean isJUnitMethod(ASTMethodDeclaration method, Object data) {
|
||||||
|
|
||||||
if (!method.isPublic() || method.isAbstract() || method.isNative() || method.isStatic()) {
|
if (!method.isPublic() || method.isAbstract() || method.isNative() || method.isStatic()) {
|
||||||
|
@ -399,6 +399,27 @@ public class TestClass extends Assert {
|
|||||||
assertNull(null);
|
assertNull(null);
|
||||||
assertThat("", containsString(""));
|
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>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
* [#1440](https://sourceforge.net/p/pmd/bugs/1440/): NPE in AvoidCallingFinalize
|
* [#1440](https://sourceforge.net/p/pmd/bugs/1440/): NPE in AvoidCallingFinalize
|
||||||
* java-imports/UnnecessaryFullyQualifiedName
|
* java-imports/UnnecessaryFullyQualifiedName
|
||||||
* [#1436](https://sourceforge.net/p/pmd/bugs/1436/): UnnecessaryFullyQualifiedName false positive on clashing static imports with enums
|
* [#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
|
* java-migrating/JUnit4TestShouldUseBeforeAnnotation
|
||||||
* [#1446](https://sourceforge.net/p/pmd/bugs/1446/): False positive with JUnit4TestShouldUseBeforeAnnotation when TestNG is used
|
* [#1446](https://sourceforge.net/p/pmd/bugs/1446/): False positive with JUnit4TestShouldUseBeforeAnnotation when TestNG is used
|
||||||
* java-naming/SuspiciousEqualsMethodName
|
* java-naming/SuspiciousEqualsMethodName
|
||||||
|
Reference in New Issue
Block a user