aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2023-01-12 09:35:20 +0100
committersonartech <sonartech@sonarsource.com>2023-01-12 20:02:51 +0000
commit118a3ed166799831e097748f2ce8e113298ad14e (patch)
tree9ea5410359990f4ef457bf0822b5b31a770d15de /server/sonar-db-dao
parent0b5343ff7744ec27ed14a90e07833319719bc9a8 (diff)
downloadsonarqube-118a3ed166799831e097748f2ce8e113298ad14e.tar.gz
sonarqube-118a3ed166799831e097748f2ce8e113298ad14e.zip
[NO JIRA] Fix quality issues related to assertions
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentKeyNewValueTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskDtoLightTest.java14
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java68
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java4
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java5
7 files changed, 49 insertions, 50 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentKeyNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentKeyNewValueTest.java
index c6cfb43bc10..45797cefe2a 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentKeyNewValueTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentKeyNewValueTest.java
@@ -34,6 +34,6 @@ public class ComponentKeyNewValueTest {
JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString());
- assertThat(jsonObject.size()).isEqualTo(3);
+ assertThat(jsonObject).hasSize(3);
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java
index 49f49500876..0eee39d9f8c 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/audit/model/ComponentNewValueTest.java
@@ -34,7 +34,7 @@ public class ComponentNewValueTest {
JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString());
- assertThat(jsonObject.size()).isEqualTo(5);
+ assertThat(jsonObject).hasSize(5);
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskDtoLightTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskDtoLightTest.java
index a218272a90b..a7d9428e2b6 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskDtoLightTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/ce/CeTaskDtoLightTest.java
@@ -44,9 +44,10 @@ public class CeTaskDtoLightTest {
@Test
public void equals_is_based_on_created_date_and_uuid() {
- assertThat(task1).isEqualTo(task2);
- assertThat(task1).isNotEqualTo(task3);
- assertThat(task1).isNotEqualTo(task4);
+ assertThat(task1)
+ .isEqualTo(task2)
+ .isNotEqualTo(task3)
+ .isNotEqualTo(task4);
}
@Test
@@ -56,8 +57,9 @@ public class CeTaskDtoLightTest {
@Test
public void compareTo_is_based_on_created_date_and_uuid() {
- assertThat(task1).isEqualByComparingTo(task2);
- assertThat(task1).isLessThan(task3);
- assertThat(task1).isLessThan(task4);
+ assertThat(task1)
+ .isEqualByComparingTo(task2)
+ .isLessThan(task3)
+ .isLessThan(task4);
}
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java
index 3369b9299f8..b168db80882 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertyDtoTest.java
@@ -27,14 +27,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
public class AnalysisPropertyDtoTest {
-
private AnalysisPropertyDto underTest;
@Test
public void null_key_should_throw_NPE() {
underTest = new AnalysisPropertyDto();
- assertThatThrownBy(() -> underTest.setKey(null))
+ assertThatThrownBy(() -> underTest.setKey(null))
.isInstanceOf(NullPointerException.class)
.hasMessage("key cannot be null");
}
@@ -74,40 +73,37 @@ public class AnalysisPropertyDtoTest {
.setKey(randomAlphanumeric(512))
.setValue(randomAlphanumeric(10000));
- assertThat(underTest).isEqualTo(
- new AnalysisPropertyDto()
- .setUuid(underTest.getUuid())
- .setAnalysisUuid(underTest.getAnalysisUuid())
- .setKey(underTest.getKey())
- .setValue(underTest.getValue()));
-
- assertThat(underTest).isNotEqualTo(
- new AnalysisPropertyDto()
- .setUuid("1" + underTest.getUuid())
- .setAnalysisUuid(underTest.getAnalysisUuid())
- .setKey(underTest.getKey())
- .setValue(underTest.getValue()));
-
- assertThat(underTest).isNotEqualTo(
- new AnalysisPropertyDto()
- .setUuid(underTest.getUuid())
- .setAnalysisUuid("1" + underTest.getAnalysisUuid())
- .setKey(underTest.getKey())
- .setValue(underTest.getValue()));
-
- assertThat(underTest).isNotEqualTo(
- new AnalysisPropertyDto()
- .setUuid(underTest.getUuid())
- .setAnalysisUuid(underTest.getAnalysisUuid())
- .setKey("1" + underTest.getKey())
- .setValue(underTest.getValue()));
-
- assertThat(underTest).isNotEqualTo(
- new AnalysisPropertyDto()
- .setUuid(underTest.getUuid())
- .setAnalysisUuid(underTest.getAnalysisUuid())
- .setKey(underTest.getKey())
- .setValue("1" + underTest.getValue()));
+ assertThat(underTest)
+ .isEqualTo(
+ new AnalysisPropertyDto()
+ .setUuid(underTest.getUuid())
+ .setAnalysisUuid(underTest.getAnalysisUuid())
+ .setKey(underTest.getKey())
+ .setValue(underTest.getValue()))
+ .isNotEqualTo(
+ new AnalysisPropertyDto()
+ .setUuid("1" + underTest.getUuid())
+ .setAnalysisUuid(underTest.getAnalysisUuid())
+ .setKey(underTest.getKey())
+ .setValue(underTest.getValue()))
+ .isNotEqualTo(
+ new AnalysisPropertyDto()
+ .setUuid(underTest.getUuid())
+ .setAnalysisUuid("1" + underTest.getAnalysisUuid())
+ .setKey(underTest.getKey())
+ .setValue(underTest.getValue()))
+ .isNotEqualTo(
+ new AnalysisPropertyDto()
+ .setUuid(underTest.getUuid())
+ .setAnalysisUuid(underTest.getAnalysisUuid())
+ .setKey("1" + underTest.getKey())
+ .setValue(underTest.getValue()))
+ .isNotEqualTo(
+ new AnalysisPropertyDto()
+ .setUuid(underTest.getUuid())
+ .setAnalysisUuid(underTest.getAnalysisUuid())
+ .setKey(underTest.getKey())
+ .setValue("1" + underTest.getValue()));
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java
index b5ed25e4fe2..12fdf75a6a7 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/period/IntervalTest.java
@@ -57,7 +57,7 @@ public class IntervalTest {
);
List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDate("2010-01-01"), DateUtils.parseDate("2011-12-31"), Calendar.MONTH);
- assertThat(intervals.size()).isEqualTo(3);
+ assertThat(intervals).hasSize(3);
assertThat(intervals.get(0).count()).isOne();
assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL));
@@ -78,7 +78,7 @@ public class IntervalTest {
List<Interval> intervals = Interval.group(snapshots,
DateUtils.parseDateTime("2010-01-01T00:00:00+0100"), DateUtils.parseDateTime("2011-12-31T00:00:00+0100"), Calendar.MONTH);
- assertThat(intervals.size()).isEqualTo(2);
+ assertThat(intervals).hasSize(2);
assertThat(intervals.get(0).count()).isOne();
assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL));
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java
index 8ea7ee818b0..a30b49e37a2 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/ActiveRuleKeyTest.java
@@ -35,7 +35,7 @@ public class ActiveRuleKeyTest {
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(key.getRuleKey()).isSameAs(ruleKey);
- assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":xoo:R1");
+ assertThat(key).hasToString(profile.getRulesProfileUuid() + ":xoo:R1");
}
@Test
@@ -45,7 +45,7 @@ public class ActiveRuleKeyTest {
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey);
assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid());
assertThat(key.getRuleKey()).isSameAs(ruleKey);
- assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":java:Key:With:Some::Colons");
+ assertThat(key).hasToString(profile.getRulesProfileUuid() + ":java:Key:With:Some::Colons");
}
@Test
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
index a93c1905629..fa3ffb89e8d 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/qualityprofile/QualityProfileExportDaoTest.java
@@ -85,8 +85,9 @@ public class QualityProfileExportDaoTest {
List<ActiveRuleDto> activeRules = activate(profile, customRule, rule);
List<ExportRuleDto> results = underTest.selectRulesByProfile(dbSession, profile);
- assertThat(results).isNotNull();
- assertThat(results).isNotEmpty();
+ assertThat(results)
+ .isNotNull()
+ .isNotEmpty();
// verify custom rule
ExportRuleDto exportCustomRuleDto = results.stream().filter(ExportRuleDto::isCustomRule).findFirst().get();