Skip to content

[java] JUnitTestsShouldIncludeAssert does not detect assertThat() when saving in variable #4765

@mrclmh

Description

@mrclmh

Affects PMD Version: 6.55.0

Rule:
JUnitTestsShouldIncludeAssert

Description:
With AssertJ you can create assert chains in fluent style. It can happen that you save a part in a variable for reuse.
The assertThat() is not detected and the rule is triggered.

Code Sample demonstrating the issue:

import static org.assertj.core.api.Assertions.assertThat;

final var dataArea = assertThat(jaxb).isNotNull()
        .extracting(JAXBElement::getValue)
        .isNotNull();

Expected outcome:

PMD should detect the assertThat. When you remove the variable, the assertThat is detected.

Running PMD through:
Gradle

Metadata

Metadata

Assignees

Labels

a:false-positivePMD flags a piece of code that is not problematic

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions