Skip to content

Commit

Permalink
Improve AutoScanTest assertions by using soft assertions (#4488)
Browse files Browse the repository at this point in the history
  • Loading branch information
johann-beleites-sonarsource authored Oct 18, 2023
1 parent aa15f59 commit cb0ab72
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.TreeSet;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.assertj.core.api.SoftAssertions;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -176,19 +177,22 @@ public void javaCheckTestSources() throws Exception {
List<IssueDiff> knownDiffs = GSON.fromJson(Files.readString(pathFor("src/test/resources/autoscan/" + DIFF_FILE + ".json")), GSON_LIST_ISSUE_DIFF_TYPE);
IssueDiff knownTotal = IssueDiff.total(knownDiffs);

assertThat(newDiffs).containsExactlyInAnyOrderElementsOf(knownDiffs);
assertThat(newTotal).isEqualTo(knownTotal);
assertThat(rulesCausingFPs).hasSize(6);
assertThat(rulesNotReporting).hasSize(7);
assertThat(rulesSilenced).hasSize(69);
SoftAssertions softly = new SoftAssertions();
softly.assertThat(newDiffs).containsExactlyInAnyOrderElementsOf(knownDiffs);
softly.assertThat(newTotal).isEqualTo(knownTotal);
softly.assertThat(rulesCausingFPs).hasSize(6);
softly.assertThat(rulesNotReporting).hasSize(7);
softly.assertThat(rulesSilenced).hasSize(69);

/**
* 4. Check total number of differences (FPs + FNs)
*
* No differences would mean that we find the same issues with and without the bytecode and libraries
*/
String differences = Files.readString(pathFor(TARGET_ACTUAL + PROJECT_KEY + "-no-binaries_differences"));
assertThat(differences).isEqualTo("Issues differences: 3335");
softly.assertThat(differences).isEqualTo("Issues differences: 3335");

softly.assertAll();
}

private static Path pathFor(String path) {
Expand Down

0 comments on commit cb0ab72

Please sign in to comment.