diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2020-12-07 15:44:01 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-09 20:07:20 +0000 |
commit | 91c611fe568a94170adb174e63940db060932bb8 (patch) | |
tree | e3772597dd8d36fade5235f282542178101b08e4 | |
parent | 5f1b82343cb99caae29ce07f316b3b6b556c8b33 (diff) | |
download | sonarqube-91c611fe568a94170adb174e63940db060932bb8.tar.gz sonarqube-91c611fe568a94170adb174e63940db060932bb8.zip |
fix assertions on incompatible types on overall code
11 files changed, 25 insertions, 38 deletions
diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index cad4904df0b..2d37e9480e5 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -665,7 +665,7 @@ public class InternalCeQueueImplTest { assertThat(dto.getComponentUuid()).isNull(); } assertThat(dto.getSubmitterUuid()).isEqualTo(taskSubmit.getSubmitterUuid()); - assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt()).isNotNull(); + assertThat(dto.getCreatedAt()).isEqualTo(dto.getUpdatedAt()); } private ComponentDto newProjectDto(String uuid) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java index 5252ab28cfe..28698489024 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java @@ -42,15 +42,14 @@ public class PropertyDtoTest { @Test public void testHashCode() { - assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode()).isNotNull(); - assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode()) - .isEqualTo(new PropertyDto().setKey("123").setComponentUuid("uuid123").hashCode()); + assertThat(new PropertyDto().setKey("123").setComponentUuid("uuid123")) + .hasSameHashCodeAs(new PropertyDto().setKey("123").setComponentUuid("uuid123")); } @Test public void testToString() { - assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setComponentUuid("uuid123").setUserUuid("456").toString()) - .isEqualTo("PropertyDto{foo:bar, value, uuid123, 456}"); + assertThat(new PropertyDto().setKey("foo:bar").setValue("value").setComponentUuid("uuid123").setUserUuid("456")) + .hasToString("PropertyDto{foo:bar, value, uuid123, 456}"); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ChildSettingsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ChildSettingsTest.java index 4e2858e70dd..7d1e6d4e541 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ChildSettingsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ChildSettingsTest.java @@ -86,7 +86,9 @@ public class ChildSettingsTest { parent.setProperty(key, randomAlphanumeric(20)); underTest.setProperty(key, randomAlphanumeric(10)); - assertThat(underTest.get(key)).isNotEqualTo(parent.getString(key)); + Optional<String> result = underTest.get(key); + assertThat(result).isPresent(); + assertThat(result.get()).isNotEqualTo(parent.getString(key)); } @Test diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java index 4d64f56da08..59d4b217e3f 100644 --- a/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java +++ b/server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java @@ -351,8 +351,6 @@ public class BuiltInQProfileUpdateImplTest { assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); - assertThat(activeRule.getCreatedAt()).isNotNull(); - assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ResultTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ResultTest.java index 429a0bdde97..6136a33a15c 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ResultTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ResultTest.java @@ -66,17 +66,17 @@ public class ResultTest { @Test public void test_text_message() { - Result.Message txtMessage = Result.Message.of("the error"); - Result.Message sameMessage = Result.Message.of("the error"); + String errorMessage = "the error"; + Result.Message txtMessage = Result.Message.of(errorMessage); + Result.Message sameMessage = Result.Message.of(errorMessage); Result.Message otherMessage = Result.Message.of("other"); - assertThat(txtMessage.toString()).contains("the error"); + assertThat(txtMessage.toString()).contains(errorMessage); assertThat(txtMessage).isEqualTo(txtMessage); assertThat(txtMessage).isEqualTo(sameMessage); assertThat(txtMessage.hashCode()).isEqualTo(txtMessage.hashCode()); assertThat(txtMessage.hashCode()).isEqualTo(sameMessage.hashCode()); assertThat(txtMessage).isNotEqualTo(otherMessage); - assertThat(txtMessage).isNotEqualTo("the error"); } @Test @@ -94,6 +94,6 @@ public class ResultTest { assertThat(msg).isNotEqualTo(msg2); assertThat(msg).isNotEqualTo(msg3); - assertThat(msg).isNotEqualTo("issue.error.123"); + assertThat(msg.text()).isNotEqualTo("issue.error.123"); } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java index 223e899e7ed..f741a145e4a 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java @@ -905,8 +905,6 @@ public class QProfileRuleImplTest { assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); - assertThat(activeRule.getCreatedAt()).isNotNull(); - assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); @@ -940,8 +938,6 @@ public class QProfileRuleImplTest { assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); - assertThat(activeRule.getCreatedAt()).isNotNull(); - assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java index 4b307e6d7d6..5103d662b27 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java @@ -218,8 +218,6 @@ public class QProfileTreeImplTest { assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); - assertThat(activeRule.getCreatedAt()).isNotNull(); - assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); @@ -253,8 +251,6 @@ public class QProfileTreeImplTest { assertThat(activeRule.getSeverityString()).isEqualTo(expectedSeverity); assertThat(activeRule.getInheritance()).isEqualTo(expectedInheritance != null ? expectedInheritance.name() : null); - assertThat(activeRule.getCreatedAt()).isNotNull(); - assertThat(activeRule.getUpdatedAt()).isNotNull(); List<ActiveRuleParamDto> params = db.getDbClient().activeRuleDao().selectParamsByActiveRuleUuid(db.getSession(), activeRule.getUuid()); assertThat(params).hasSize(expectedParams.size()); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java index 458323bfbd2..622615132aa 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java @@ -22,13 +22,14 @@ package org.sonar.api.batch.scm; import org.junit.Test; import java.util.Date; +import org.junit.jupiter.api.Assertions; import static org.assertj.core.api.Assertions.assertThat; public class BlameLineTest { @Test - public void testBlameLine() { + public void testEqualBlameLine() { Date date = new Date(); BlameLine line1 = new BlameLine().date(date).revision("1").author("foo"); BlameLine line1b = new BlameLine().date(date).revision("1").author("foo"); @@ -38,12 +39,11 @@ public class BlameLineTest { assertThat(line1.date()).isEqualTo(date); assertThat(line1.revision()).isEqualTo("1"); - assertThat(line1).isEqualTo(line1); + Assertions.assertEquals(line1, line1); assertThat(line1).isNotEqualTo(null); assertThat(line1).isEqualTo(line1b); assertThat(line1.hashCode()).isEqualTo(line1b.hashCode()); assertThat(line1).isNotEqualTo(line2); - assertThat(line1).isNotEqualTo("foo"); assertThat(line1.toString()).contains("revision=1,author=foo"); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java index d95da63a476..2f86737ee1a 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java @@ -30,7 +30,7 @@ public class CategoryTest { assertThat(new Category("Licenses")).isEqualTo(new Category("licenses")); // Just to raise coverage - assertThat(new Category("Licenses")).isNotEqualTo("Licenses"); + assertThat(new Category("Licenses").key()).isNotEqualTo("Licenses"); } @Test diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java index 0ca116e2626..53c407de4bc 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.function.Consumer; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.junit.rules.ExpectedException; import org.sonar.api.rule.RuleKey; import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile; @@ -56,7 +57,7 @@ public class BuiltInQualityProfilesDefinitionTest { } @Test - public void sanityCheck() { + public void sanityEqualCheck() { Map<String, Map<String, BuiltInQualityProfile>> profiles = define(c -> { NewBuiltInQualityProfile profile1 = c.createBuiltInQualityProfile("Foo1", "xoo"); NewBuiltInActiveRule rule = profile1.activateRule("repo", "rule"); @@ -65,9 +66,9 @@ public class BuiltInQualityProfilesDefinitionTest { profile2.done(); NewBuiltInQualityProfile profile3 = c.createBuiltInQualityProfile("Foo1", "xoo2"); profile3.done(); - assertThat(profile1).isEqualTo(profile1); + Assertions.assertEquals(profile1, profile1); assertThat(profile1).isNotEqualTo(null); - assertThat(profile1).isNotEqualTo("Foo"); + assertThat(profile1.name()).isNotEqualTo("Foo"); assertThat(profile1).isNotEqualTo(profile2); assertThat(profile1).isNotEqualTo(profile3); assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode()); @@ -79,7 +80,7 @@ public class BuiltInQualityProfilesDefinitionTest { BuiltInQualityProfile profile3 = profiles.get("xoo2").get("Foo1"); assertThat(profile1).isEqualTo(profile1); assertThat(profile1).isNotEqualTo(null); - assertThat(profile1).isNotEqualTo("Foo"); + assertThat(profile1.name()).isNotEqualTo("Foo"); assertThat(profile1).isNotEqualTo(profile2); assertThat(profile1).isNotEqualTo(profile3); assertThat(profile1.hashCode()).isNotEqualTo(profile2.hashCode()); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java index 3c8f2c1cd7c..4fcf716522e 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java @@ -29,9 +29,11 @@ import java.net.URL; import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.junit.Assert; import org.junit.Assume; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.sonar.api.rule.RuleKey; @@ -45,6 +47,7 @@ import org.sonar.api.impl.server.RulesDefinitionContext; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; @RunWith(DataProviderRunner.class) public class RulesDefinitionTest { @@ -135,10 +138,6 @@ public class RulesDefinitionTest { RulesDefinition.Rule otherRule = repo.rule("ABC"); assertThat(otherRule.htmlDescription()).isNull(); assertThat(otherRule.markdownDescription()).isEqualTo("ABC"); - - // test equals() and hashCode() - assertThat(rule).isEqualTo(rule).isNotEqualTo(otherRule).isNotEqualTo("NPE").isNotEqualTo(null); - assertThat(rule.hashCode()).isEqualTo(rule.hashCode()); } @Test @@ -221,10 +220,6 @@ public class RulesDefinitionTest { RulesDefinition.Rule otherRule = repo.rule("ABC"); assertThat(otherRule.htmlDescription()).isNull(); assertThat(otherRule.markdownDescription()).isEqualTo("ABC"); - - // test equals() and hashCode() - assertThat(rule).isEqualTo(rule).isNotEqualTo(otherRule).isNotEqualTo("NPE").isNotEqualTo(null); - assertThat(rule.hashCode()).isEqualTo(rule.hashCode()); } @Test |