Affects PMD Version:
6.20.0
Rule:
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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4