]> source.dussan.org Git - sonarqube.git/commitdiff
[NO-JIRA] Fix unstable Unit Test for PurgeCommands
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Fri, 28 Jan 2022 14:25:24 +0000 (11:25 -0300)
committersonartech <sonartech@sonarsource.com>
Fri, 28 Jan 2022 20:03:09 +0000 (20:03 +0000)
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java

index 9d617149791005f75fdaea1bc748c1a3855610ac..5321db94f83dd09d4411c25ad85ead50e673df7d 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.db.purge;
 import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Random;
@@ -541,17 +542,20 @@ public class PurgeCommandsTest {
     RuleDefinitionDto rule = dbTester.rules().insert();
     dbTester.components().insertComponent(projectOrView);
     ComponentDto file = dbTester.components().insertComponent(newFileDto(projectOrView));
+    List<String> issueKeys = new ArrayList<>();
     int count = 5;
     IntStream.range(0, count).forEach(i -> {
       IssueDto issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(projectOrView));
       dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
       issue = dbTester.issues().insertIssue(t -> t.setRule(rule).setProject(projectOrView).setComponent(file));
       dbTester.issues().insertNewCodeReferenceIssue(newCodeReferenceIssue(issue));
+      issueKeys.add("'" + issue.getKey() + "'");
     });
 
     underTest.deleteIssues(projectOrView.uuid());
 
-    assertThat(dbTester.countRowsOfTable("NEW_CODE_REFERENCE_ISSUES")).isZero();
+    assertThat(dbTester.countSql("select count(uuid) from new_code_reference_issues where issue_key in (" +
+      String.join(", ", issueKeys) + ")")).isZero();
   }
 
   @Test
@@ -862,14 +866,14 @@ public class PurgeCommandsTest {
 
   @DataProvider
   public static Object[] projects() {
-    return new Object[] {
+    return new Object[]{
       ComponentTesting.newPrivateProjectDto(), ComponentTesting.newPublicProjectDto(),
     };
   }
 
   @DataProvider
   public static Object[] views() {
-    return new Object[] {
+    return new Object[]{
       ComponentTesting.newPortfolio(), ComponentTesting.newApplication()
     };
   }