Affects PMD Version:
6.48.0+
7.0.0
Rule:
JUnitTestsShouldIncludeAssert
Description:
Rule has false positives when using @ExtendWith(SoftAssertionsExtension.class) for AssertJ soft assertions, which call assertAll automatically so it's not required to call it explicitly in the tests.
Code Sample demonstrating the issue:
import org.assertj.core.api.SoftAssertions;
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions;
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ExtendWith({SoftAssertionsExtension.class})
class ShouldIncludeAssertTest {
@InjectSoftAssertions private SoftAssertions softly;
@Test
void falsePositive1() {
softly.assertThat(false).isTrue();
softly.assertThat(true).isFalse();
}
@Test
void falsePositive2() {
SoftAssertions.assertSoftly(
softly2 -> {
softly2.assertThat(false).isTrue();
softly2.assertThat(true).isFalse();
});
}
}
Expected outcome:
No violations reported, but PMD incorrectly reports a violation for both falsePositive1 and falsePositive2.
Running PMD through: Gradle
Affects PMD Version:
6.48.0+
7.0.0
Rule:
JUnitTestsShouldIncludeAssert
Description:
Rule has false positives when using
@ExtendWith(SoftAssertionsExtension.class)for AssertJ soft assertions, which callassertAllautomatically so it's not required to call it explicitly in the tests.Code Sample demonstrating the issue:
Expected outcome:
No violations reported, but PMD incorrectly reports a violation for both
falsePositive1andfalsePositive2.Running PMD through: Gradle