diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-03 14:31:46 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2014-03-03 16:10:19 +0100 |
commit | 40eb62e293a469571e041d99be84a3ce66a965cd (patch) | |
tree | e9753617a4e09f0fd7a425ea3f118dff312ce123 /sonar-plugin-api | |
parent | a3244de0ece1e348744b69437e064d109b97ed08 (diff) | |
download | sonarqube-40eb62e293a469571e041d99be84a3ce66a965cd.tar.gz sonarqube-40eb62e293a469571e041d99be84a3ce66a965cd.zip |
Fix quality flaws
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java index 22ad1125a36..ddf60903360 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java @@ -141,6 +141,8 @@ public class WorkDurationTest { assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add( WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY) ).minutes()).isEqualTo(30); + + assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(null).minutes()).isEqualTo(10); } @Test @@ -162,6 +164,8 @@ public class WorkDurationTest { // 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(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).subtract(null).minutes()).isEqualTo(10); } @Test @@ -173,4 +177,25 @@ public class WorkDurationTest { assertThat(result.minutes()).isEqualTo(0); assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY); } + + @Test + public void test_equals_and_hashcode() throws Exception { + WorkDuration duration = WorkDuration.createFromLong(28800, HOURS_IN_DAY); + 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(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()); + } + + @Test + public void test_toString() throws Exception { + assertThat(WorkDuration.createFromLong(28800, HOURS_IN_DAY).toString()).isNotNull(); + } } |