False positive for "Squid:S2970 Add a call to 'assertAll' after all 'assertThat'" when using SoftAssertions.assertSoftly

java
sonarqube
sonarlint
(Jeffrey) #1

This rule incorrectly warns that ‘assertAll’ needs to be called for AssertJ assertions in this example. Note that the static method SoftAssertions.assertSoftly calls the ‘assertAll()’ method.

I am seeing the false positive in both SonarQube version 6.7.6 and also when using the IntelliJ SonarLint plugin version 4.0.2.3009.

Here is a very simple example:

import org.assertj.core.api.SoftAssertions;
import org.junit.Test;

public class FalsePositiveTest {

  @Test
  public void falsePositive() {
    SoftAssertions.assertSoftly(softly -> {
      softly.assertThat(true).isTrue();
      softly.assertThat(false).isFalse();
    });
  } // The violation is marked here since it apparently doesn't know 'assertAll()' was called
}