False positive for “Squid:S2970 Add a call to ‘assertAll’ after all ‘assertThat’” when using AssertJ's Junit 5 SoftAssertionExtension

This rule incorrectly warns that ‘assertAll’ needs to be called for AssertJ assertions when using the SoftAssertionExtension Junit 5 extension (which calls it automatically). Please see the documentation for various ways for the “assertAll” to be called automatically: https://assertj.github.io/doc/#assertj-core-soft-assertions

I am seeing the false positive in both SonarQube v8.0.x and SonarJava v6.2.

Hello @sdavids, thanks for the feedback.

Indeed, this feature is not yet supported, I created a ticket (SONARJAVA-3324) to keep track of it.

I had a quick look at the other ways to avoid calling assertAll(), and it seems that we are supporting them correctly.

Best,
Quentin

Hello,

UPDATE: After reading the assertj docs, I’ve seen that is a deprecated mechanism.

Is the usage of the following extension,

@RegisterExtension
public JUnitJupiterSoftAssertions softly = new JUnitJupiterSoftAssertions();

also supported correctly?
Thanks.

Hello @lucasvc,

At first glance, I would say that we will not support correctly this way writing a soft assertion.

Out of curiosity, were did you find the documentation stating that this mechanism is deprecated?

Hi @Quentin,

In the latest class javadoc.

Okay, I understand what is happening. My confusion was that they deprecated JUnitJupiterSoftAssertions but still propose an example with it as an alternative (in the doc you just linked).

In fact, it seems that first, there is a deprecation message:

Deprecated.
use SoftAssertionsExtension instead.

And then, the old description of the rule (that you can see in an older version of the doc):

Same as SoftAssertions , but with the following differences: […]

I admit that this is confusing…
All in all, it means that code such as:

@RegisterExtension
public JUnitJupiterSoftAssertions softly = new JUnitJupiterSoftAssertions();

Is not supported by the rule, but is in fact the mechanism that is deprecated, not the other way around.

I hope it makes sense and I did not miss something!

Best,
Quentin