S2698 suffers from multiple problems related to issue reporting that we should improve.
- duplicate issues:
This code will report one issue for each matches.assertThat("ABC") .matches("A") .matches("B") .matches("C");
- the whole assertion is highlighted
assertThrows(IllegalArgumentException.class, () -> //Huge code...)); // Everything is highlighted!!
Can we do better? Only highlight one method call?
- confusing behavior when the message is misplaced for fest assert (and AssertJ once
SONARJAVA-3349will be done)
This call
assertThat("").isEqualTo("").as("Message");
will highlight
assertThat("").isEqualTo("")
claiming that a message is missing, it is not trivial to understand that it is actually misplaced.
RSPEC-5833 will report that "as()" will not be applied, but this rule could still report that it is misplaced (or simply say to add a message before the assertion). In addition, highlighting should be on the assertion method name. (isEqualTo() in this case)
- FP when a generic assertion is not an assertion predicate:
org.assertj.core.api.Assertions.assertThat("").usingComparator(null).as("a").isEqualTo(222);
- contributes to
-
MMF-2016 [Java] Test code quality: AssertJ related rules
-
- Closed
-
- relates to
-
RSPEC-2698 Test assertions should include messages
- Active