Affects PMD Version:
6.48.0+
7.0.0
Rule:
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
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