diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2021-11-18 16:45:02 -0600 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-20 20:03:51 +0000 |
commit | 3f9445c25962f914ccdd889c002ddd8e19b0cf89 (patch) | |
tree | eb4f34a62b7164a71fd0bbe34d6f59621a687d8d /server/sonar-ce-task | |
parent | aa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff) | |
download | sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip |
Improve code quality
Diffstat (limited to 'server/sonar-ce-task')
4 files changed, 32 insertions, 27 deletions
diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java index 4389facfb02..01043cae25b 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskComponentTest.java @@ -64,14 +64,15 @@ public class CeTaskComponentTest { String somethingElse = randomAlphabetic(5); CeTask.Component underTest = new CeTask.Component(uuid, key, name); - assertThat(underTest).isEqualTo(underTest); - assertThat(underTest).isEqualTo(new CeTask.Component(uuid, key, name)); - assertThat(underTest).isNotEqualTo(null); - assertThat(underTest).isNotEqualTo(new Object()); - assertThat(underTest).isNotEqualTo(new CeTask.Component(somethingElse, key, name)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, somethingElse, name)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, key, somethingElse)); - assertThat(underTest).isNotEqualTo(new CeTask.Component(uuid, key, null)); + assertThat(underTest) + .isEqualTo(underTest) + .isEqualTo(new CeTask.Component(uuid, key, name)) + .isNotNull() + .isNotEqualTo(new Object()) + .isNotEqualTo(new CeTask.Component(somethingElse, key, name)) + .isNotEqualTo(new CeTask.Component(uuid, somethingElse, name)) + .isNotEqualTo(new CeTask.Component(uuid, key, somethingElse)) + .isNotEqualTo(new CeTask.Component(uuid, key, null)); } @Test @@ -82,13 +83,15 @@ public class CeTaskComponentTest { String somethingElse = randomAlphabetic(5); CeTask.Component underTest = new CeTask.Component(uuid, key, name); - assertThat(underTest.hashCode()).isEqualTo(underTest.hashCode()); - assertThat(underTest.hashCode()).isEqualTo(new CeTask.Component(uuid, key, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new Object().hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(somethingElse, key, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, somethingElse, name).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, key, somethingElse).hashCode()); - assertThat(underTest.hashCode()).isNotEqualTo(new CeTask.Component(uuid, key, null).hashCode()); + assertThat(underTest) + .hasSameHashCodeAs(underTest) + .hasSameHashCodeAs(new CeTask.Component(uuid, key, name)); + assertThat(underTest.hashCode()) + .isNotEqualTo(new Object().hashCode()) + .isNotEqualTo(new CeTask.Component(somethingElse, key, name).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, somethingElse, name).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, key, somethingElse).hashCode()) + .isNotEqualTo(new CeTask.Component(uuid, key, null).hashCode()); } @DataProvider diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java index 08b12549b77..f2cb3601bdb 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/CeTaskTest.java @@ -121,8 +121,9 @@ public class CeTaskTest { assertThat(task1.equals(task1)).isTrue(); assertThat(task1.equals(task1bis)).isTrue(); assertThat(task1.equals(task2)).isFalse(); - assertThat(task1.hashCode()).isEqualTo(task1.hashCode()); - assertThat(task1.hashCode()).isEqualTo(task1bis.hashCode()); + assertThat(task1) + .hasSameHashCodeAs(task1) + .hasSameHashCodeAs(task1bis); } @Test @@ -148,12 +149,13 @@ public class CeTaskTest { CeTask.User user2 = new CeTask.User("UUID_2", null); CeTask.User user1_diff_login = new CeTask.User("UUID_1", "LOGIN"); - assertThat(user1).isEqualTo(user1); - assertThat(user1).isEqualTo(user1bis); - assertThat(user1).isNotEqualTo(user2); assertThat(user1.equals(null)).isFalse(); - assertThat(user1.hashCode()).isEqualTo(user1.hashCode()); - assertThat(user1.hashCode()).isEqualTo(user1bis.hashCode()); - assertThat(user1.hashCode()).isEqualTo(user1_diff_login.hashCode()); + assertThat(user1) + .isEqualTo(user1) + .isEqualTo(user1bis) + .isNotEqualTo(user2) + .hasSameHashCodeAs(user1) + .hasSameHashCodeAs(user1bis) + .hasSameHashCodeAs(user1_diff_login); } } diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java index a4c6834d9a3..f75b4f80424 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/container/TaskContainerImplTest.java @@ -72,7 +72,7 @@ public class TaskContainerImplTest { assertThat(defaultStartable.startCalls).isZero(); assertThat(defaultStartable.stopCalls).isZero(); - assertThat(eagerStartable.startCalls).isEqualTo(1); + assertThat(eagerStartable.startCalls).isOne(); assertThat(eagerStartable.stopCalls).isZero(); } @@ -90,8 +90,8 @@ public class TaskContainerImplTest { assertThat(defaultStartable.startCalls).isZero(); assertThat(defaultStartable.stopCalls).isZero(); - assertThat(eagerStartable.startCalls).isEqualTo(1); - assertThat(eagerStartable.stopCalls).isEqualTo(1); + assertThat(eagerStartable.startCalls).isOne(); + assertThat(eagerStartable.stopCalls).isOne(); } public static class DefaultStartable implements Startable { diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java index 13190b4392f..66adb122df5 100644 --- a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/log/CeTaskMessagesMessageTest.java @@ -60,7 +60,7 @@ public class CeTaskMessagesMessageTest { .isEqualTo(new Message(text, timestamp)) .isNotEqualTo(new Message(text + "รง", timestamp)) .isNotEqualTo(new Message(text, timestamp + 10_999L)) - .isNotEqualTo(null) + .isNotNull() .isNotEqualTo(new Object()); } |