Fixed bug - JUnitTestsShouldIncludeAssert now detects Junit 4 Assert.assert... constructs

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6753 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Xavier Le Vourch
2008-12-13 00:12:54 +00:00
parent ffb1131fe0
commit 8c64498325
3 changed files with 34 additions and 3 deletions

View File

@ -7,6 +7,7 @@ Fixed bug 2338341 - ArrayIndexOutOfBoundsException in CPD (on Ruby)
Fixed bug 2315599 - False +: UseSingleton with class containing constructor
Fixed bug 1955852 - false positives for UnusedPrivateMethod & UnusedLocalVariable
Fixed bug 2404700 - UseSingleton should not act on enums
Fixed bug - JUnitTestsShouldIncludeAssert now detects Junit 4 Assert.assert... constructs
October 12, 2008 - 4.2.4:

View File

@ -223,4 +223,34 @@ public class Foo {
}
]]></code>
</test-code>
</test-data>
<test-code>
<description><![CDATA[
Junit 4 static import
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import static org.junit.Assert.assertFalse;
import org.junit.Test;
public class AssertTest {
@Test public void testFalse() {
assertFalse(1 == 2);
}
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
Junit 4 test using Assert.assert...
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import org.junit.Assert;
import org.junit.Test;
public class AssertTest {
@Test public void testTrue() {
Assert.assertTrue(1 != 2);
}
}
]]></code>
</test-code>
</test-data>

View File

@ -59,8 +59,8 @@ public class JUnitTestsShouldContainAsserts extends AbstractJUnitRule {
if (pe.jjtGetNumChildren()> 0 && pe.jjtGetChild(0) instanceof ASTPrimaryPrefix) {
ASTPrimaryPrefix pp = (ASTPrimaryPrefix) pe.jjtGetChild(0);
if (pp.jjtGetNumChildren()>0 && pp.jjtGetChild(0) instanceof ASTName) {
ASTName n = (ASTName) pp.jjtGetChild(0);
if (n.getImage()!=null && (n.getImage().startsWith("assert") || n.getImage().startsWith("fail") )) {
String img = ((ASTName) pp.jjtGetChild(0)).getImage();
if (img != null && (img.startsWith("assert") || img.startsWith("fail") || img.startsWith("Assert.assert") || img.startsWith("Assert.fail") )) {
return true;
}
}