]> source.dussan.org Git - sonarqube.git/commitdiff
fix assertions on incompatible types on overall code
authorPierre <pierre.guillot@sonarsource.com>
Mon, 7 Dec 2020 14:44:01 +0000 (15:44 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 9 Dec 2020 20:07:20 +0000 (20:07 +0000)
server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertyDtoTest.java
server/sonar-server-common/src/test/java/org/sonar/server/setting/ChildSettingsTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/qualityprofile/BuiltInQProfileUpdateImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ResultTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileRuleImplTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualityprofile/QProfileTreeImplTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/scm/BlameLineTest.java
sonar-plugin-api/src/test/java/org/sonar/api/config/CategoryTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/profile/BuiltInQualityProfilesDefinitionTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java

index cad4904df0b7bdbccbab153b1981a5caac9eefac..2d37e9480e5e3f7b4abb67bda94730c860a87ec8 100644 (file)
@@ -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) {
index 5252ab28cfeb1d57e8d7aa8b2c4b5b909e08ca84..28698489024244e5645a01bbe6ace71c1187350e 100644 (file)
@@ -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
index 4e2858e70dd49ee5dfe616c7f59b151d7db36d44..7d1e6d4e54146e2592dd89a5fad5c8a6e0fb0ed9 100644 (file)
@@ -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
index 4d64f56da087d7812aed591adb49884a5e5f6e00..59d4b217e3f44e4167a4520bc8dbb2454e8dcad7 100644 (file)
@@ -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());
index 429a0bdde97d88e70960b885f32021c6fc2f1a30..6136a33a15c86afa94746d7280edd96edb9593fe 100644 (file)
@@ -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");
   }
 }
index 223e899e7ed1afaf71c22a5682ac5e1789bd2198..f741a145e4a456b744a166940db542e00643ceb5 100644 (file)
@@ -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());
index 4b307e6d7d614d78b691a8ae06316f387c65734f..5103d662b27644fa3b03a96dbea01aaaac73141b 100644 (file)
@@ -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());
index 458323bfbd22001fb4da3501298b550084113fac..622615132aa7b7673e5a842f768eb0fcb7dcbf25 100644 (file)
@@ -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");
   }
index d95da63a4763e9cbedbd41adfceb8a917255c385..2f86737ee1af5d073b1e0ca529e64562247acaa2 100644 (file)
@@ -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
index 0ca116e26265be01acb2f4d504acadf460b6626f..53c407de4bc320971fb4c97d60549fc21bbbd3be 100644 (file)
@@ -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());
index 3c8f2c1cd7cbe9f6272d9ed77eef98c9d649c9b4..4fcf716522e811764806ad36820e6735d64c72e2 100644 (file)
@@ -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