Affects PMD Version:
6.20.0
Rule:
JUnitTestsShouldIncludeAssert
Description:
asserts in static method calls and in lambdas are ignored, triggering false positives
Code Sample demonstrating the issue:
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import com.fasterxml.jackson.databind.JsonNode;
@Test
public void testDemo() {
JsonNode jsonNode = assertSuccessResponse();
final int totalFieldsCount = jsonNode.get("count").asInt();
jsonNode.get("data").forEach(item -> assertTrue(item.size() <= totalFieldsCount));
}
public static JsonNode assertSuccessResponse() {
JsonNode jsonNode = doStuffToBuildTheJsonNode();
assertTrue(jsonNode.hasNonNull("count"));
assertTrue(jsonNode.hasNonNull("data"));
assertTrue(jsonNode.get("count").asInt() > 0);
assertEquals(jsonNode.get("count").asInt(), jsonNode.get("data").size());
return jsonNode;
}
(In the actual failing code, the assertSuccessResponse method is in a different class as a static helper method).
[INFO] PMD Failure: TheTest:98 Rule:JUnitTestsShouldIncludeAssert Priority:3 JUnit tests should include assert() or fail().
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven, OpenJDK from AdoptOpenJDK 1.8
Affects PMD Version:
6.20.0
Rule:
JUnitTestsShouldIncludeAssert
Description:
asserts in static method calls and in lambdas are ignored, triggering false positives
Code Sample demonstrating the issue:
(In the actual failing code, the assertSuccessResponse method is in a different class as a static helper method).
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven, OpenJDK from AdoptOpenJDK 1.8