]> source.dussan.org Git - sonarqube.git/commitdiff
[NO-JIRA] make log assertions resilient to unexpected log messages
authorSteve Marion <steve.marion@sonarsource.com>
Wed, 29 Nov 2023 15:18:49 +0000 (16:18 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 29 Nov 2023 20:02:37 +0000 (20:02 +0000)
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/metric/ReportMetricValidatorImplTest.java

index 8ce7b773f6663173903139cb51ed974252de3739..3c23166e673e63cf85e00f7bd2f51a0e96f1421c 100644 (file)
@@ -44,6 +44,8 @@ public class ReportMetricValidatorImplTest {
 
   ScannerMetrics scannerMetrics = mock(ScannerMetrics.class);
 
+  private static final String expectedLog = "The metric 'metric_key' is ignored and should not be send in the batch report";
+
   @Before
   public void before() {
     logTester.setLevel(Level.DEBUG);
@@ -55,7 +57,7 @@ public class ReportMetricValidatorImplTest {
     ReportMetricValidator validator = new ReportMetricValidatorImpl(scannerMetrics);
 
     assertThat(validator.validate(METRIC_KEY)).isTrue();
-    assertThat(logTester.logs()).isEmpty();
+    assertThat(logTester.logs()).noneMatch(expectedLog::equals);
   }
 
   @Test
@@ -64,7 +66,8 @@ public class ReportMetricValidatorImplTest {
     ReportMetricValidator validator = new ReportMetricValidatorImpl(scannerMetrics);
 
     assertThat(validator.validate(METRIC_KEY)).isFalse();
-    assertThat(logTester.logs()).containsOnly("The metric 'metric_key' is ignored and should not be send in the batch report");
+
+    assertThat(logTester.logs()).contains(expectedLog);
   }
 
   @Test
@@ -73,8 +76,8 @@ public class ReportMetricValidatorImplTest {
     ReportMetricValidator validator = new ReportMetricValidatorImpl(scannerMetrics);
 
     assertThat(validator.validate(METRIC_KEY)).isFalse();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs()).filteredOn(expectedLog::equals).hasSize(1);
     assertThat(validator.validate(METRIC_KEY)).isFalse();
-    assertThat(logTester.logs()).hasSize(1);
+    assertThat(logTester.logs()).filteredOn(expectedLog::equals).hasSize(1);
   }
 }