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 /sonar-plugin-api-impl | |
parent | aa640be9e2b9cfa2c027ef0768940b31ebb5536c (diff) | |
download | sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.tar.gz sonarqube-3f9445c25962f914ccdd889c002ddd8e19b0cf89.zip |
Improve code quality
Diffstat (limited to 'sonar-plugin-api-impl')
10 files changed, 58 insertions, 56 deletions
diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java index b8baf578ee8..81f0cf06059 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/batch/sensor/internal/SensorContextTester.java @@ -260,7 +260,6 @@ public class SensorContextTester implements SensorContext { public Integer lineHits(String fileKey, int line) { return sensorStorage.coverageByComponent.getOrDefault(fileKey, Collections.emptyList()).stream() .map(c -> c.hitsByLine().get(line)) - .flatMap(Stream::of) .filter(Objects::nonNull) .reduce(null, SensorContextTester::sumOrNull); } @@ -274,7 +273,6 @@ public class SensorContextTester implements SensorContext { public Integer conditions(String fileKey, int line) { return sensorStorage.coverageByComponent.getOrDefault(fileKey, Collections.emptyList()).stream() .map(c -> c.conditionsByLine().get(line)) - .flatMap(Stream::of) .filter(Objects::nonNull) .reduce(null, SensorContextTester::maxOrNull); } @@ -283,7 +281,6 @@ public class SensorContextTester implements SensorContext { public Integer coveredConditions(String fileKey, int line) { return sensorStorage.coverageByComponent.getOrDefault(fileKey, Collections.emptyList()).stream() .map(c -> c.coveredConditionsByLine().get(line)) - .flatMap(Stream::of) .filter(Objects::nonNull) .reduce(null, SensorContextTester::maxOrNull); } diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java index 153788121a3..08132cf0cf0 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/impl/ws/SimpleGetRequest.java @@ -68,7 +68,7 @@ public class SimpleGetRequest extends Request { @Override public boolean hasParam(String key) { - return params.keySet().contains(key); + return params.containsKey(key); } @Override diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java index f052506340a..72ba4d2407b 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/DefaultInputFileTest.java @@ -156,14 +156,16 @@ public class DefaultInputFileTest { DefaultInputFile f1a = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), (f) -> mock(Metadata.class)); DefaultInputFile f2 = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), "src/Bar.php", null), (f) -> mock(Metadata.class)); - assertThat(f1).isEqualTo(f1); - assertThat(f1).isEqualTo(f1a); - assertThat(f1).isNotEqualTo(f2); + assertThat(f1) + .isEqualTo(f1) + .isEqualTo(f1a) + .isNotEqualTo(f2); assertThat(f1.equals("foo")).isFalse(); assertThat(f1.equals(null)).isFalse(); - assertThat(f1.hashCode()).isEqualTo(f1.hashCode()); - assertThat(f1.hashCode()).isEqualTo(f1a.hashCode()); + assertThat(f1) + .hasSameHashCodeAs(f1) + .hasSameHashCodeAs(f1a); } @Test @@ -176,7 +178,7 @@ public class DefaultInputFileTest { public void checkValidPointer() { Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {9, 15}, 16); DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata)); - assertThat(file.newPointer(1, 0).line()).isEqualTo(1); + assertThat(file.newPointer(1, 0).line()).isOne(); assertThat(file.newPointer(1, 0).lineOffset()).isZero(); // Don't fail file.newPointer(1, 9); @@ -213,10 +215,10 @@ public class DefaultInputFileTest { public void checkValidPointerUsingGlobalOffset() { Metadata metadata = new Metadata(2, 2, "", new int[] {0, 10}, new int[] {8, 15}, 16); DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata)); - assertThat(file.newPointer(0).line()).isEqualTo(1); + assertThat(file.newPointer(0).line()).isOne(); assertThat(file.newPointer(0).lineOffset()).isZero(); - assertThat(file.newPointer(9).line()).isEqualTo(1); + assertThat(file.newPointer(9).line()).isOne(); // Ignore eol characters assertThat(file.newPointer(9).lineOffset()).isEqualTo(8); @@ -250,7 +252,7 @@ public class DefaultInputFileTest { Metadata metadata = new FileMetadata(mock(AnalysisWarnings.class)).readMetadata(new StringReader("bla bla a\nabcde")); DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata)); - assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 1)).start().line()).isEqualTo(1); + assertThat(file.newRange(file.newPointer(1, 0), file.newPointer(2, 1)).start().line()).isOne(); // Don't fail file.newRange(file.newPointer(1, 0), file.newPointer(1, 1)); file.newRange(file.newPointer(1, 0), file.newPointer(1, 9)); @@ -276,9 +278,9 @@ public class DefaultInputFileTest { Metadata metadata = new FileMetadata(mock(AnalysisWarnings.class)).readMetadata(new StringReader("bla bla a\nabcde\n\nabc")); DefaultInputFile file = new DefaultInputFile(new DefaultIndexedFile("ABCDE", Paths.get("module"), MODULE_RELATIVE_PATH, null), f -> f.setMetadata(metadata)); - assertThat(file.selectLine(1).start().line()).isEqualTo(1); + assertThat(file.selectLine(1).start().line()).isOne(); assertThat(file.selectLine(1).start().lineOffset()).isZero(); - assertThat(file.selectLine(1).end().line()).isEqualTo(1); + assertThat(file.selectLine(1).end().line()).isOne(); assertThat(file.selectLine(1).end().lineOffset()).isEqualTo(9); // Don't fail when selecting empty line diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/FileMetadataTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/FileMetadataTest.java index 8fd67f6ed6b..ba1a19ca34c 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/FileMetadataTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/fs/internal/fs/FileMetadataTest.java @@ -60,7 +60,7 @@ public class FileMetadataTest { FileUtils.touch(tempFile); Metadata metadata = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(tempFile), StandardCharsets.UTF_8, tempFile.getName()); - assertThat(metadata.lines()).isEqualTo(1); + assertThat(metadata.lines()).isOne(); assertThat(metadata.nonBlankLines()).isZero(); assertThat(metadata.hash()).isNotEmpty(); assertThat(metadata.originalLineStartOffsets()).containsOnly(0); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java index 84f57635817..dc8a63ac101 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultExternalIssueTest.java @@ -67,7 +67,7 @@ public class DefaultExternalIssueTest { .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) - .remediationEffortMinutes(10l) + .remediationEffortMinutes(10L) .type(RuleType.BUG) .severity(Severity.BLOCKER); @@ -75,8 +75,8 @@ public class DefaultExternalIssueTest { assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("external_repo", "rule")); assertThat(issue.engineId()).isEqualTo("repo"); assertThat(issue.ruleId()).isEqualTo("rule"); - assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); - assertThat(issue.remediationEffort()).isEqualTo(10l); + assertThat(issue.primaryLocation().textRange().start().line()).isOne(); + assertThat(issue.remediationEffort()).isEqualTo(10L); assertThat(issue.type()).isEqualTo(RuleType.BUG); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); @@ -94,7 +94,7 @@ public class DefaultExternalIssueTest { .on(project) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) - .remediationEffortMinutes(10l) + .remediationEffortMinutes(10L) .type(RuleType.BUG) .severity(Severity.BLOCKER); @@ -103,7 +103,7 @@ public class DefaultExternalIssueTest { assertThat(issue.engineId()).isEqualTo("repo"); assertThat(issue.ruleId()).isEqualTo("rule"); assertThat(issue.primaryLocation().textRange()).isNull(); - assertThat(issue.remediationEffort()).isEqualTo(10l); + assertThat(issue.remediationEffort()).isEqualTo(10L); assertThat(issue.type()).isEqualTo(RuleType.BUG); assertThat(issue.severity()).isEqualTo(Severity.BLOCKER); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); @@ -122,7 +122,7 @@ public class DefaultExternalIssueTest { .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) - .remediationEffortMinutes(10l) + .remediationEffortMinutes(10L) .severity(Severity.BLOCKER); assertThatThrownBy(() -> issue.save()) @@ -138,7 +138,7 @@ public class DefaultExternalIssueTest { .on(inputFile) .at(inputFile.selectLine(1))) .forRule(RuleKey.of("repo", "rule")) - .remediationEffortMinutes(10l) + .remediationEffortMinutes(10L) .type(RuleType.BUG) .severity(Severity.BLOCKER); @@ -156,7 +156,7 @@ public class DefaultExternalIssueTest { .at(inputFile.selectLine(1)) .message("Wrong way!")) .forRule(RuleKey.of("repo", "rule")) - .remediationEffortMinutes(10l) + .remediationEffortMinutes(10L) .type(RuleType.BUG); assertThatThrownBy(() -> issue.save()) diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java index 25199bd9509..9f39ed11dfe 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssueTest.java @@ -71,7 +71,7 @@ public class DefaultIssueTest { assertThat(issue.primaryLocation().inputComponent()).isEqualTo(inputFile); assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule")); - assertThat(issue.primaryLocation().textRange().start().line()).isEqualTo(1); + assertThat(issue.primaryLocation().textRange().start().line()).isOne(); assertThat(issue.gap()).isEqualTo(10.0); assertThat(issue.primaryLocation().message()).isEqualTo("Wrong way!"); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MapSettingsTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MapSettingsTest.java index 41c28b0529f..6b672fc7b3e 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MapSettingsTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MapSettingsTest.java @@ -209,7 +209,7 @@ public class MapSettingsTest { public void default_number_values_are_zero() { Settings settings = new MapSettings(); assertThat(settings.getInt("foo")).isZero(); - assertThat(settings.getLong("foo")).isEqualTo(0L); + assertThat(settings.getLong("foo")).isZero(); } @Test diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java index d7503e7765c..93f873b40ff 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/MultivaluePropertyTest.java @@ -83,7 +83,7 @@ public class MultivaluePropertyTest { @Test @UseDataProvider("plains") public void trimFieldsAndRemoveEmptyFields_ignores_EmptyFields(String str) { - assertThat(trimFieldsAndRemoveEmptyFields("")).isEqualTo(""); + assertThat(trimFieldsAndRemoveEmptyFields("")).isEmpty(); assertThat(trimFieldsAndRemoveEmptyFields(str)).isEqualTo(str); assertThat(trimFieldsAndRemoveEmptyFields(',' + str)).isEqualTo(str); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2Test.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2Test.java index a96ff9579c0..b2c298427dc 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2Test.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/AlwaysIncreasingSystem2Test.java @@ -97,7 +97,7 @@ public class AlwaysIncreasingSystem2Test { if (initialValue != null) { assertThat(now).isEqualTo(initialValue); } else { - assertThat(now).isGreaterThan(0); + assertThat(now).isPositive(); } previousValue = now; } else { diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java index 30e9219a1da..af1da5fabd5 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/impl/utils/WorkDurationTest.java @@ -34,9 +34,9 @@ public class WorkDurationTest { @Test public void create_from_days_hours_minutes() { WorkDuration workDuration = WorkDuration.create(1, 1, 1, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); - assertThat(workDuration.hours()).isEqualTo(1); - assertThat(workDuration.minutes()).isEqualTo(1); + assertThat(workDuration.days()).isOne(); + assertThat(workDuration.hours()).isOne(); + assertThat(workDuration.minutes()).isOne(); assertThat(workDuration.toMinutes()).isEqualTo(ONE_DAY_IN_MINUTES + ONE_HOUR_IN_MINUTES + ONE_MINUTE); assertThat(workDuration.hoursInDay()).isEqualTo(HOURS_IN_DAY); } @@ -44,7 +44,7 @@ public class WorkDurationTest { @Test public void create_from_value_and_unit() { WorkDuration result = WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); - assertThat(result.days()).isEqualTo(1); + assertThat(result.days()).isOne(); assertThat(result.hours()).isZero(); assertThat(result.minutes()).isZero(); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); @@ -60,15 +60,15 @@ public class WorkDurationTest { WorkDuration workDuration = WorkDuration.createFromMinutes(ONE_MINUTE, HOURS_IN_DAY); assertThat(workDuration.days()).isZero(); assertThat(workDuration.hours()).isZero(); - assertThat(workDuration.minutes()).isEqualTo(1); + assertThat(workDuration.minutes()).isOne(); workDuration = WorkDuration.createFromMinutes(ONE_HOUR_IN_MINUTES, HOURS_IN_DAY); assertThat(workDuration.days()).isZero(); - assertThat(workDuration.hours()).isEqualTo(1); + assertThat(workDuration.hours()).isOne(); assertThat(workDuration.minutes()).isZero(); workDuration = WorkDuration.createFromMinutes(ONE_DAY_IN_MINUTES, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.days()).isOne(); assertThat(workDuration.hours()).isZero(); assertThat(workDuration.minutes()).isZero(); } @@ -79,17 +79,17 @@ public class WorkDurationTest { WorkDuration workDuration = WorkDuration.createFromLong(1L, HOURS_IN_DAY); assertThat(workDuration.days()).isZero(); assertThat(workDuration.hours()).isZero(); - assertThat(workDuration.minutes()).isEqualTo(1); + assertThat(workDuration.minutes()).isOne(); // 1 hour workDuration = WorkDuration.createFromLong(100L, HOURS_IN_DAY); assertThat(workDuration.days()).isZero(); - assertThat(workDuration.hours()).isEqualTo(1); + assertThat(workDuration.hours()).isOne(); assertThat(workDuration.minutes()).isZero(); // 1 day workDuration = WorkDuration.createFromLong(10000L, HOURS_IN_DAY); - assertThat(workDuration.days()).isEqualTo(1); + assertThat(workDuration.days()).isOne(); assertThat(workDuration.hours()).isZero(); assertThat(workDuration.minutes()).isZero(); } @@ -113,26 +113,27 @@ public class WorkDurationTest { @Test public void convert_to_working_long() { - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toLong()).isEqualTo(2l); - assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(400l); - assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10200l); - assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10000l); - assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toLong()).isEqualTo(20000l); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toLong()).isEqualTo(2L); + assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(400L); + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10200L); + assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toLong()).isEqualTo(10000L); + assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toLong()).isEqualTo(20000L); } @Test public void add() { // 4h + 5h = 1d 1h - WorkDuration result = WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); - assertThat(result.days()).isEqualTo(1); - assertThat(result.hours()).isEqualTo(1); + WorkDuration result = WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY) + .add(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY)); + assertThat(result.days()).isOne(); + assertThat(result.hours()).isOne(); assertThat(result.minutes()).isZero(); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); // 40 m + 30m = 1h 10m result = WorkDuration.createFromValueAndUnit(40, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)); assertThat(result.days()).isZero(); - assertThat(result.hours()).isEqualTo(1); + assertThat(result.hours()).isOne(); assertThat(result.minutes()).isEqualTo(10); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); @@ -161,8 +162,9 @@ public class WorkDurationTest { assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); // 30m - 20m = 10m - assertThat(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)) - .minutes()).isEqualTo(10); + assertThat( + WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)) + .minutes()).isEqualTo(10); assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(null).minutes()).isEqualTo(10); } @@ -171,7 +173,7 @@ public class WorkDurationTest { public void multiply() { // 5h * 2 = 1d 2h WorkDuration result = WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).multiply(2); - assertThat(result.days()).isEqualTo(1); + assertThat(result.days()).isOne(); assertThat(result.hours()).isEqualTo(2); assertThat(result.minutes()).isZero(); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); @@ -183,13 +185,14 @@ public class WorkDurationTest { WorkDuration durationWithSameValue = WorkDuration.createFromLong(28800, HOURS_IN_DAY); WorkDuration durationWithDifferentValue = WorkDuration.createFromLong(14400, HOURS_IN_DAY); - assertThat(duration).isEqualTo(duration); - assertThat(durationWithSameValue).isEqualTo(duration); + assertThat(duration) + .isNotNull() + .hasSameHashCodeAs(duration) + .isEqualTo(duration); + assertThat(durationWithSameValue) + .hasSameHashCodeAs(duration) + .isEqualTo(duration); assertThat(durationWithDifferentValue).isNotEqualTo(duration); - assertThat(duration).isNotEqualTo(null); - - assertThat(duration.hashCode()).isEqualTo(duration.hashCode()); - assertThat(durationWithSameValue.hashCode()).isEqualTo(duration.hashCode()); assertThat(durationWithDifferentValue.hashCode()).isNotEqualTo(duration.hashCode()); } |