From 3f9445c25962f914ccdd889c002ddd8e19b0cf89 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 18 Nov 2021 16:45:02 -0600 Subject: Improve code quality --- .../sonar/server/ce/http/CeHttpClientImplTest.java | 2 +- .../sonar/server/es/MigrationEsClientImplTest.java | 2 +- .../email/EmailNotificationChannelTest.java | 2 +- .../DatabaseMigrationImplConcurrentAccessTest.java | 2 +- .../platform/monitoring/EsIndexesSectionTest.java | 4 ++-- .../cluster/EsClusterStateSectionTest.java | 2 +- .../platform/monitoring/cluster/NodeInfoTest.java | 5 +++-- .../monitoring/cluster/NodeSystemSectionTest.java | 2 +- .../qualitygate/ProjectsInWarningDaemonTest.java | 4 ++-- .../org/sonar/server/rule/RegisterRulesTest.java | 14 ++++++------- .../server/rule/SingleDeprecatedRuleKeyTest.java | 23 ++++++++++++---------- .../java/org/sonar/server/search/BaseDocTest.java | 2 +- .../org/sonar/server/util/DateCollectorTest.java | 2 +- 13 files changed, 35 insertions(+), 31 deletions(-) (limited to 'server/sonar-webserver-core') diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java index 9c4bfcac841..6fcf1eceff0 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/ce/http/CeHttpClientImplTest.java @@ -61,7 +61,7 @@ public class CeHttpClientImplTest { public void retrieveSystemInfo_returns_absent_if_process_is_down() { Optional info = underTest.retrieveSystemInfo(); - assertThat(info.isPresent()).isFalse(); + assertThat(info).isEmpty(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java index dba91bdcc4d..3e1d8059e98 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/es/MigrationEsClientImplTest.java @@ -81,7 +81,7 @@ public class MigrationEsClientImplTest { assertThat(loadExistingIndices()).toIterable().contains("as"); ImmutableOpenMap> mappings = mappings(); MappingMetadata mapping = mappings.get("as").get("s"); - assertThat(countMappingFields(mapping)).isEqualTo(1); + assertThat(countMappingFields(mapping)).isOne(); assertThat(field(mapping, "new_field")).isNotNull(); assertThat(logTester.logs(LoggerLevel.INFO)) diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java index 2d7f20d524f..43f051298f5 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/notification/email/EmailNotificationChannelTest.java @@ -338,7 +338,7 @@ public class EmailNotificationChannelTest { int count = underTest.deliverAll(Collections.singleton(request)); - assertThat(count).isEqualTo(1); + assertThat(count).isOne(); assertThat(smtpServer.getMessages()).hasSize(1); assertThat((String) smtpServer.getMessages().iterator().next().getMimeMessage().getContent()) .contains(emailMessage11.getMessage()); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java index 55248bea7e4..65aeb9a61f7 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/db/migration/DatabaseMigrationImplConcurrentAccessTest.java @@ -80,7 +80,7 @@ public class DatabaseMigrationImplConcurrentAccessTest { pool.awaitTermination(2, TimeUnit.SECONDS); - assertThat(triggerCount.get()).isEqualTo(1); + assertThat(triggerCount.get()).isOne(); } private class CallStartit implements Runnable { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java index 248f8e4b93b..7313625670c 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/EsIndexesSectionTest.java @@ -49,8 +49,8 @@ public class EsIndexesSectionTest { ProtobufSystemInfo.Section section = underTest.toProtobuf(); // one index "issues" - assertThat(attribute(section, "Index issues - Docs").getLongValue()).isEqualTo(0L); - assertThat(attribute(section, "Index issues - Shards").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Index issues - Docs").getLongValue()).isZero(); + assertThat(attribute(section, "Index issues - Shards").getLongValue()).isPositive(); assertThat(attribute(section, "Index issues - Store Size").getStringValue()).isNotNull(); } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java index 75ad980d23f..1e5a2c4db24 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/EsClusterStateSectionTest.java @@ -42,7 +42,7 @@ public class EsClusterStateSectionTest { @Test public void test_attributes() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); - assertThat(attribute(section, "Nodes").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Nodes").getLongValue()).isPositive(); assertThat(attribute(section, "State").getStringValue()).isIn("RED", "YELLOW", "GREEN"); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java index 5a88794980d..a0aabab52cc 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeInfoTest.java @@ -35,8 +35,9 @@ public class NodeInfoTest { assertThat(foo.equals(bar)).isFalse(); assertThat(bar.equals(bar2)).isTrue(); - assertThat(bar.hashCode()).isEqualTo(bar.hashCode()); - assertThat(bar.hashCode()).isEqualTo(bar2.hashCode()); + assertThat(bar) + .hasSameHashCodeAs(bar) + .hasSameHashCodeAs(bar2); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java index 66d6c18f60a..0e4b6f631d7 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/platform/monitoring/cluster/NodeSystemSectionTest.java @@ -74,7 +74,7 @@ public class NodeSystemSectionTest { public void return_nb_of_processors() { ProtobufSystemInfo.Section section = underTest.toProtobuf(); - assertThat(attribute(section, "Processors").getLongValue()).isGreaterThan(0); + assertThat(attribute(section, "Processors").getLongValue()).isPositive(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java index 78c49687110..d7d2ad96e61 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/qualitygate/ProjectsInWarningDaemonTest.java @@ -182,8 +182,8 @@ public class ProjectsInWarningDaemonTest { underTest.notifyStart(); waitForValueToBeComputed(1L); - assertThat(projectsInWarning.count()).isEqualTo(1L); - assertThat(countNumberOfProjectsInWarning()).isEqualTo(0L); + assertThat(projectsInWarning.count()).isOne(); + assertThat(countNumberOfProjectsInWarning()).isZero(); } private void waitForValueToBeComputed(long expectedValue) throws InterruptedException { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 5eb8a2d39c9..cbcaf854a7c 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -448,7 +448,7 @@ public class RegisterRulesTest { assertThat(rule1.getName()).isEqualTo("Name2"); assertThat(rule1.getDescription()).isEqualTo("Description"); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()).getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -509,7 +509,7 @@ public class RegisterRulesTest { RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository, ruleKey1)); SearchIdResult searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()); assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid()); - assertThat(searchRule1.getTotal()).isEqualTo(1); + assertThat(searchRule1.getTotal()).isOne(); system.setNow(DATE2.getTime()); execute(context -> { @@ -529,7 +529,7 @@ public class RegisterRulesTest { SearchIdResult searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()); assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid()); - assertThat(searchRule2.getTotal()).isEqualTo(1); + assertThat(searchRule2.getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -551,7 +551,7 @@ public class RegisterRulesTest { RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RuleKey.of(repository1, ruleKey)); SearchIdResult searchRule1 = ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()); assertThat(searchRule1.getUuids()).containsOnly(rule1.getUuid()); - assertThat(searchRule1.getTotal()).isEqualTo(1); + assertThat(searchRule1.getTotal()).isOne(); system.setNow(DATE2.getTime()); execute(context -> { @@ -571,7 +571,7 @@ public class RegisterRulesTest { SearchIdResult searchRule2 = ruleIndex.search(new RuleQuery().setQueryText("Name2"), new SearchOptions()); assertThat(searchRule2.getUuids()).containsOnly(rule2.getUuid()); - assertThat(searchRule2.getTotal()).isEqualTo(1); + assertThat(searchRule2.getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Name1"), new SearchOptions()).getTotal()).isZero(); } @@ -687,7 +687,7 @@ public class RegisterRulesTest { assertThat(rule1.getName()).isEqualTo("Name"); assertThat(rule1.getDescription()).isEqualTo("Desc2"); - assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isOne(); assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc1"), new SearchOptions()).getTotal()).isZero(); } @@ -753,7 +753,7 @@ public class RegisterRulesTest { rule = dbClient.ruleDao().selectOrFailByKey(db.getSession(), RULE_KEY1); assertThat(rule.getStatus()).isEqualTo(RuleStatus.BETA); - assertThat(ruleIndex.search(new RuleQuery().setKey(RULE_KEY1.toString()), new SearchOptions()).getTotal()).isEqualTo(1); + assertThat(ruleIndex.search(new RuleQuery().setKey(RULE_KEY1.toString()), new SearchOptions()).getTotal()).isOne(); } @Test diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java index 0675f348f1e..a9a95853054 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/rule/SingleDeprecatedRuleKeyTest.java @@ -104,19 +104,22 @@ public class SingleDeprecatedRuleKeyTest { SingleDeprecatedRuleKey singleDeprecatedRuleKey1 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1); SingleDeprecatedRuleKey singleDeprecatedRuleKey2 = SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2); - assertThat(singleDeprecatedRuleKey1).isEqualTo(singleDeprecatedRuleKey1); - assertThat(singleDeprecatedRuleKey1).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)); - assertThat(singleDeprecatedRuleKey1).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); + assertThat(singleDeprecatedRuleKey1) + .isEqualTo(singleDeprecatedRuleKey1) + .isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)) + .isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); assertThat(singleDeprecatedRuleKey2).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2)); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(singleDeprecatedRuleKey1.hashCode()); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1).hashCode()); - assertThat(singleDeprecatedRuleKey1.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid).hashCode()); - assertThat(singleDeprecatedRuleKey2.hashCode()).isEqualTo(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2).hashCode()); + assertThat(singleDeprecatedRuleKey1) + .hasSameHashCodeAs(singleDeprecatedRuleKey1) + .hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1)) + .hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto1WithoutUuid)); + assertThat(singleDeprecatedRuleKey2).hasSameHashCodeAs(SingleDeprecatedRuleKey.from(deprecatedRuleKeyDto2)); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(null); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(""); - assertThat(singleDeprecatedRuleKey1).isNotEqualTo(singleDeprecatedRuleKey2); + assertThat(singleDeprecatedRuleKey1) + .isNotNull() + .isNotEqualTo("") + .isNotEqualTo(singleDeprecatedRuleKey2); assertThat(singleDeprecatedRuleKey2).isNotEqualTo(singleDeprecatedRuleKey1); assertThat(singleDeprecatedRuleKey1.hashCode()).isNotEqualTo(singleDeprecatedRuleKey2.hashCode()); diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java index db2094a43c4..a66b14091fe 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/search/BaseDocTest.java @@ -150,6 +150,6 @@ public class BaseDocTest { assertThat((Map) fields.get(index.getJoinField())) .isEqualTo(ImmutableMap.of("name", relationType.getName(), "parent", "miam")); - assertThat(fields.get("indexType")).isEqualTo(relationType.getName()); + assertThat(fields).containsEntry("indexType", relationType.getName()); } } diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java index 97e64be8a61..d2d49499b64 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/util/DateCollectorTest.java @@ -30,7 +30,7 @@ public class DateCollectorTest { @Test public void max_is_zero_if_no_dates() { - assertThat(collector.getMax()).isEqualTo(0L); + assertThat(collector.getMax()).isZero(); } @Test -- cgit v1.2.3