aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2020-12-04 11:34:36 +0100
committersonartech <sonartech@sonarsource.com>2020-12-09 20:07:21 +0000
commit720c19e83f2299a848c18c6921a3c22281b87eb6 (patch)
treefdbdc8b99a62296fbb7eec5812ed336e70ea9e3d /server/sonar-db-migration
parent5380a8080eb0d52981739fc3fe5459c66b204f11 (diff)
downloadsonarqube-720c19e83f2299a848c18c6921a3c22281b87eb6.tar.gz
sonarqube-720c19e83f2299a848c18c6921a3c22281b87eb6.zip
Code smells test fixes
Diffstat (limited to 'server/sonar-db-migration')
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DeleteSecurityReviewRatingMeasuresTest.java10
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java22
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java22
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java6
-rw-r--r--server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/RemoveFilesFavouritesFromPropertiesTest.java4
5 files changed, 30 insertions, 34 deletions
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DeleteSecurityReviewRatingMeasuresTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DeleteSecurityReviewRatingMeasuresTest.java
index 162cac3e402..c814efb5171 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DeleteSecurityReviewRatingMeasuresTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DeleteSecurityReviewRatingMeasuresTest.java
@@ -49,7 +49,7 @@ public class DeleteSecurityReviewRatingMeasuresTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DeleteSecurityReviewRatingMeasuresTest.class, "schema.sql");
- private DataChange underTest = new DeleteSecurityReviewRatingMeasures(db.database());
+ private final DataChange underTest = new DeleteSecurityReviewRatingMeasures(db.database());
@Before
public void before() {
@@ -228,8 +228,8 @@ public class DeleteSecurityReviewRatingMeasuresTest {
underTest.execute();
- assertThat(db.countRowsOfTable(PROJECT_MEASURES_TABLE_NAME)).isEqualTo(0);
- assertThat(db.countRowsOfTable(LIVE_MEASURES_TABLE_NAME)).isEqualTo(0);
+ assertThat(db.countRowsOfTable(PROJECT_MEASURES_TABLE_NAME)).isZero();
+ assertThat(db.countRowsOfTable(LIVE_MEASURES_TABLE_NAME)).isZero();
}
private void generateOtherMetricsLiveMeasures(String componentUuid) {
@@ -248,12 +248,12 @@ public class DeleteSecurityReviewRatingMeasuresTest {
private void assertSecurityReviewRatingLiveMeasuresDeleted() {
assertThat(db.countSql("select count(uuid) from LIVE_MEASURES where metric_id = " + SECURITY_REVIEW_RATING_METRIC_ID))
- .isEqualTo(0);
+ .isZero();
}
private void assertSecurityReviewRatingMeasuresDeleted() {
assertThat(db.countSql("select count(id) from project_measures where metric_id = " + SECURITY_REVIEW_RATING_METRIC_ID))
- .isEqualTo(0);
+ .isZero();
}
private void insertMeasure(int id, int metricId, String componentUuid) {
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java
index 9ede542c649..5b4904d88f7 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/DropSecurityHotSpotsInReviewStatusTest.java
@@ -27,7 +27,6 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DataChange;
@@ -42,12 +41,10 @@ public class DropSecurityHotSpotsInReviewStatusTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(DropSecurityHotSpotsInReviewStatusTest.class, "schema.sql");
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = System2.INSTANCE;
+ private final System2 system2 = System2.INSTANCE;
- private DataChange underTest = new DropSecurityHotSpotsInReviewStatus(db.database(), system2);
+ private final DataChange underTest = new DropSecurityHotSpotsInReviewStatus(db.database(), system2);
@Test
public void should_change_IN_REVIEW_statuses_only() throws SQLException {
@@ -75,22 +72,23 @@ public class DropSecurityHotSpotsInReviewStatusTest {
@Test
public void should_not_fail_if_no_issues() throws SQLException {
underTest.execute();
- assertThat(db.countRowsOfTable("issues")).isEqualTo(0);
+ assertThat(db.countRowsOfTable("issues")).isZero();
}
private void assertIssueChanged(int issueId) {
List<Map<String, Object>> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId));
assertThat(row).hasSize(1);
- assertThat(row.get(0).get("STATUS"))
- .isEqualTo("TO_REVIEW");
+ assertThat(row.get(0))
+ .containsEntry("STATUS", "TO_REVIEW");
List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" +
" from issue_changes where issue_key = '%s'", "issue-key-" + issueId));
assertThat(changelogRows).hasSize(1);
Map<String, Object> changelogRow = changelogRows.get(0);
- assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff");
- assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("status=IN_REVIEW|TO_REVIEW");
+ assertThat(changelogRow)
+ .containsEntry("CHANGE_TYPE", "diff")
+ .containsEntry("CHANGE_DATA", "status=IN_REVIEW|TO_REVIEW");
assertThat(changelogRow.get("CREATED_AT")).isNotNull();
assertThat(changelogRow.get("UPDATED_AT")).isNotNull();
@@ -100,8 +98,8 @@ public class DropSecurityHotSpotsInReviewStatusTest {
private void assertIssueNotChanged(int issueId, String expectedStatus) {
List<Map<String, Object>> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId));
assertThat(row).hasSize(1);
- assertThat(row.get(0).get("STATUS"))
- .isEqualTo(expectedStatus);
+ assertThat(row.get(0))
+ .containsEntry("STATUS", expectedStatus);
List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" +
" from issue_changes where issue_key = '%s'", "issue-key-" + issueId));
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java
index 50cba019e05..6c66eb18fdb 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v82/MigrateManualVulnerabilitiesToSecurityHotSpotsTest.java
@@ -29,7 +29,6 @@ import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.sonar.api.utils.System2;
import org.sonar.db.CoreDbTester;
import org.sonar.server.platform.db.migration.step.DataChange;
@@ -47,12 +46,10 @@ public class MigrateManualVulnerabilitiesToSecurityHotSpotsTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(MigrateManualVulnerabilitiesToSecurityHotSpotsTest.class, "schema.sql");
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
- private System2 system2 = System2.INSTANCE;
+ private final System2 system2 = System2.INSTANCE;
- private DataChange underTest = new MigrateManualVulnerabilitiesToSecurityHotSpots(db.database(), system2);
+ private final DataChange underTest = new MigrateManualVulnerabilitiesToSecurityHotSpots(db.database(), system2);
@Test
public void should_migrate_manual_vulnerabilities_only() throws SQLException {
@@ -92,22 +89,23 @@ public class MigrateManualVulnerabilitiesToSecurityHotSpotsTest {
@Test
public void should_not_fail_if_no_issues() throws SQLException {
underTest.execute();
- assertThat(db.countRowsOfTable("issues")).isEqualTo(0);
+ assertThat(db.countRowsOfTable("issues")).isZero();
}
private void assertIssueChanged(int issueId) {
List<Map<String, Object>> row = db.select(String.format("select status from issues where kee = '%s'", "issue-key-" + issueId));
assertThat(row).hasSize(1);
- assertThat(row.get(0).get("STATUS"))
- .isEqualTo("TO_REVIEW");
+ assertThat(row.get(0))
+ .containsEntry("STATUS", "TO_REVIEW");
List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" +
" from issue_changes where issue_key = '%s'", "issue-key-" + issueId));
assertThat(changelogRows).hasSize(1);
Map<String, Object> changelogRow = changelogRows.get(0);
- assertThat(changelogRow.get("CHANGE_TYPE")).isEqualTo("diff");
- assertThat(changelogRow.get("CHANGE_DATA")).isEqualTo("type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW");
+ assertThat(changelogRow)
+ .containsEntry("CHANGE_TYPE", "diff")
+ .containsEntry("CHANGE_DATA", "type=VULNERABILITY|SECURITY_HOTSPOT,status=OPEN|TO_REVIEW");
assertThat(changelogRow.get("CREATED_AT")).isNotNull();
assertThat(changelogRow.get("UPDATED_AT")).isNotNull();
@@ -121,8 +119,8 @@ public class MigrateManualVulnerabilitiesToSecurityHotSpotsTest {
Map<String, Object> issueData = row.get(0);
assertThat(issueData.get("STATUS"))
.isNull();
- assertThat(issueData.get("ISSUE_TYPE"))
- .isEqualTo(expectedType);
+ assertThat(issueData)
+ .containsEntry("ISSUE_TYPE", expectedType);
List<Map<String, Object>> changelogRows = db.select(String.format("select change_type, change_data, created_at, updated_at, issue_change_creation_date" +
" from issue_changes where issue_key = '%s'", "issue-key-" + issueId));
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java
index ddda3597887..d5a8512c7b1 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v83/PopulateSummaryCommentEnabledColumnForGitHubTest.java
@@ -35,16 +35,16 @@ public class PopulateSummaryCommentEnabledColumnForGitHubTest {
@Rule
public CoreDbTester db = CoreDbTester.createForSchema(PopulateSummaryCommentEnabledColumnForGitHubTest.class, "schema.sql");
- private System2 system = System2.INSTANCE;
+ private final System2 system = System2.INSTANCE;
- private DataChange underTest = new PopulateSummaryCommentEnabledColumnForGitHub(db.database(), system);
+ private final DataChange underTest = new PopulateSummaryCommentEnabledColumnForGitHub(db.database(), system);
@Test
public void does_not_fail_if_alm_settings_are_empty() throws SQLException {
underTest.execute();
assertThat(db.countSql("select count(uuid) from project_alm_settings where summary_comment_enabled is null"))
- .isEqualTo(0);
+ .isZero();
// re-entrant migration
underTest.execute();
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/RemoveFilesFavouritesFromPropertiesTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/RemoveFilesFavouritesFromPropertiesTest.java
index 0e9f472c641..5a02f58326f 100644
--- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/RemoveFilesFavouritesFromPropertiesTest.java
+++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v84/RemoveFilesFavouritesFromPropertiesTest.java
@@ -43,7 +43,7 @@ public class RemoveFilesFavouritesFromPropertiesTest {
@Rule
public CoreDbTester dbTester = CoreDbTester.createForSchema(RemoveFilesFavouritesFromPropertiesTest.class, "schema.sql");
- private DataChange underTest = new RemoveFilesFavouritesFromProperties(dbTester.database());
+ private final DataChange underTest = new RemoveFilesFavouritesFromProperties(dbTester.database());
private static final String APPLICATION_UUID_1 = Uuids.createFast();
private static final String PROJECT_UUID_2 = Uuids.createFast();
@@ -89,7 +89,7 @@ public class RemoveFilesFavouritesFromPropertiesTest {
underTest.execute();
- assertThat(dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME)).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable(PROPERTIES_TABLE_NAME)).isZero();
}
@Test