From cb0ab720e336e9dd9b46770b2e6584b976a36f45 Mon Sep 17 00:00:00 2001 From: Johann Beleites Date: Wed, 18 Oct 2023 11:05:58 +0200 Subject: [PATCH] Improve AutoScanTest assertions by using soft assertions (#4488) --- .../java/org/sonar/java/it/AutoScanTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java b/its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java index f5bf3a6a683..cbfa62d69a8 100644 --- a/its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java +++ b/its/ruling/src/test/java/org/sonar/java/it/AutoScanTest.java @@ -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; @@ -176,11 +177,12 @@ public void javaCheckTestSources() throws Exception { List 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) @@ -188,7 +190,9 @@ public void javaCheckTestSources() throws Exception { * 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) {