A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2147 below:

[java] JUnitTestsShouldIncludeAssert - false positives with lambdas and static methods · Issue #2147 · pmd/pmd · GitHub

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


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