aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-12 18:14:50 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-12 18:14:50 +0100
commitea621e0a3b22a0f31655bf203aa80260418fb567 (patch)
tree39e45fc65ef10e01158f1ec63c97ab1305f8ffc6 /sonar-plugin-api/src/test
parent37456dfe4a5f06a0b835e72c644861f14d3022ff (diff)
downloadsonarqube-ea621e0a3b22a0f31655bf203aa80260418fb567.tar.gz
sonarqube-ea621e0a3b22a0f31655bf203aa80260418fb567.zip
Replace WorkUnit by WorkDuration for technical debt
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java6
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java8
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java12
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java56
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java172
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkUnitTest.java53
6 files changed, 249 insertions, 58 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
index 1b385766ac4..0df487f777c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/issue/internal/DefaultIssueTest.java
@@ -25,7 +25,7 @@ import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.IssueComment;
import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.WorkUnit;
+import org.sonar.api.utils.WorkDuration;
import java.text.SimpleDateFormat;
import java.util.List;
@@ -50,7 +50,7 @@ public class DefaultIssueTest {
.setMessage("a message")
.setLine(7)
.setEffortToFix(1.2d)
- .setTechnicalDebt(new WorkUnit.Builder().setDays(1).build())
+ .setTechnicalDebt(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, 8))
.setActionPlanKey("BCDE")
.setStatus(Issue.STATUS_CLOSED)
.setResolution(Issue.RESOLUTION_FIXED)
@@ -78,7 +78,7 @@ public class DefaultIssueTest {
assertThat(issue.message()).isEqualTo("a message");
assertThat(issue.line()).isEqualTo(7);
assertThat(issue.effortToFix()).isEqualTo(1.2d);
- assertThat(issue.technicalDebt()).isEqualTo(new WorkUnit.Builder().setDays(1).build());
+ assertThat(issue.technicalDebt()).isEqualTo(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, 8));
assertThat(issue.actionPlanKey()).isEqualTo("BCDE");
assertThat(issue.status()).isEqualTo(Issue.STATUS_CLOSED);
assertThat(issue.resolution()).isEqualTo(Issue.RESOLUTION_FIXED);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java
index f3bda181038..918b5918f18 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/batch/internal/DefaultRequirementTest.java
@@ -47,8 +47,8 @@ public class DefaultRequirementTest {
.setCharacteristic(characteristic)
.setRootCharacteristic(root)
.setFunction("linear_offset")
- .setFactor(new WorkUnit.Builder().setMinutes(2).build())
- .setOffset(new WorkUnit.Builder().setHours(1).build())
+ .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
+ .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
.setCreatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"))
.setUpdatedAt(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
@@ -57,8 +57,8 @@ public class DefaultRequirementTest {
assertThat(requirement.characteristic()).isEqualTo(characteristic);
assertThat(requirement.rootCharacteristic()).isEqualTo(root);
assertThat(requirement.function()).isEqualTo("linear_offset");
- assertThat(requirement.factor()).isEqualTo(new WorkUnit.Builder().setMinutes(2).build());
- assertThat(requirement.offset()).isEqualTo(new WorkUnit.Builder().setHours(1).build());
+ assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+ assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
assertThat(requirement.createdAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
assertThat(requirement.updatedAt()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2013-08-19"));
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java
index 72835e0705b..6cdb209c18f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/technicaldebt/server/internal/DefaultCharacteristicTest.java
@@ -56,8 +56,8 @@ public class DefaultCharacteristicTest {
.setId(1)
.setRuleKey(RuleKey.of("repo", "rule"))
.setFunction("linear_offset")
- .setFactor(new WorkUnit.Builder().setMinutes(2).build())
- .setOffset(new WorkUnit.Builder().setHours(1).build())
+ .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
+ .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
.setRootId(3)
.setParentId(2);
@@ -67,8 +67,8 @@ public class DefaultCharacteristicTest {
assertThat(requirement.order()).isNull();
assertThat(requirement.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
assertThat(requirement.function()).isEqualTo("linear_offset");
- assertThat(requirement.factor()).isEqualTo(new WorkUnit.Builder().setMinutes(2).build());
- assertThat(requirement.offset()).isEqualTo(new WorkUnit.Builder().setHours(1).build());
+ assertThat(requirement.factor()).isEqualTo(WorkUnit.create(2d, WorkUnit.MINUTES));
+ assertThat(requirement.offset()).isEqualTo(WorkUnit.create(1d, WorkUnit.HOURS));
assertThat(requirement.parentId()).isEqualTo(2);
assertThat(requirement.rootId()).isEqualTo(3);
}
@@ -92,8 +92,8 @@ public class DefaultCharacteristicTest {
.setId(1)
.setRuleKey(RuleKey.of("repo", "rule"))
.setFunction("linear_offset")
- .setFactor(new WorkUnit.Builder().setMinutes(2).build())
- .setOffset(new WorkUnit.Builder().setHours(1).build())
+ .setFactor(WorkUnit.create(2d, WorkUnit.MINUTES))
+ .setOffset(WorkUnit.create(1d, WorkUnit.HOURS))
.setRootId(3)
.setParentId(2);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java
new file mode 100644
index 00000000000..88e21e9a704
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationFactoryTest.java
@@ -0,0 +1,56 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.utils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class WorkDurationFactoryTest {
+
+ WorkDurationFactory factory;
+
+ @Before
+ public void setUp() throws Exception {
+ Settings settings = new Settings();
+ settings.setProperty(CoreProperties.HOURS_IN_DAY, 8);
+ factory = new WorkDurationFactory(settings);
+ }
+
+ @Test
+ public void create_from_working_value() throws Exception {
+ // 1 working day -> 8 hours
+ assertThat(factory.createFromWorkingValue(1, WorkDuration.UNIT.DAYS).toSeconds()).isEqualTo(8*60*60);
+ // 8 hours
+ assertThat(factory.createFromWorkingValue(8, WorkDuration.UNIT.HOURS).toSeconds()).isEqualTo(8*60*60);
+ }
+
+ @Test
+ public void create_from_working_long() throws Exception {
+ WorkDuration workDuration = factory.createFromWorkingLong(1l);
+ assertThat(workDuration.days()).isEqualTo(0);
+ assertThat(workDuration.hours()).isEqualTo(0);
+ assertThat(workDuration.minutes()).isEqualTo(1);
+ }
+}
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
new file mode 100644
index 00000000000..affb52a1b17
--- /dev/null
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkDurationTest.java
@@ -0,0 +1,172 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.sonar.api.utils;
+
+import org.junit.Test;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class WorkDurationTest {
+
+ private static final int HOURS_IN_DAY = 8;
+
+ @Test
+ public void create_from_days_hours_minutes() throws Exception {
+ 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.toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60 + 1 * 60 * 60 + 60);
+ assertThat(workDuration.hoursInDay()).isEqualTo(HOURS_IN_DAY);
+ }
+
+ @Test
+ public void create_from_value_and_unit() throws Exception {
+ WorkDuration result = WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY);
+ assertThat(result.days()).isEqualTo(1);
+ assertThat(result.hours()).isEqualTo(0);
+ assertThat(result.minutes()).isEqualTo(0);
+ assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY);
+ assertThat(result.toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60);
+
+ assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toSeconds()).isEqualTo(1 * HOURS_IN_DAY * 60 * 60);
+ assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toSeconds()).isEqualTo(1 * 60 * 60);
+ assertThat(WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toSeconds()).isEqualTo(60);
+ }
+
+ @Test
+ public void create_from_seconds() throws Exception {
+ WorkDuration workDuration = WorkDuration.createFromSeconds(60, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(0);
+ assertThat(workDuration.hours()).isEqualTo(0);
+ assertThat(workDuration.minutes()).isEqualTo(1);
+
+ workDuration = WorkDuration.createFromSeconds(60 * 60, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(0);
+ assertThat(workDuration.hours()).isEqualTo(1);
+ assertThat(workDuration.minutes()).isEqualTo(0);
+
+ workDuration = WorkDuration.createFromSeconds(HOURS_IN_DAY * 60 * 60, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(1);
+ assertThat(workDuration.hours()).isEqualTo(0);
+ assertThat(workDuration.minutes()).isEqualTo(0);
+ }
+
+ @Test
+ public void create_from_working_long() throws Exception {
+ // 1 minute
+ WorkDuration workDuration = WorkDuration.createFromLong(1l, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(0);
+ assertThat(workDuration.hours()).isEqualTo(0);
+ assertThat(workDuration.minutes()).isEqualTo(1);
+
+ // 1 hour
+ workDuration = WorkDuration.createFromLong(100l, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(0);
+ assertThat(workDuration.hours()).isEqualTo(1);
+ assertThat(workDuration.minutes()).isEqualTo(0);
+
+ // 1 day
+ workDuration = WorkDuration.createFromLong(10000l, HOURS_IN_DAY);
+ assertThat(workDuration.days()).isEqualTo(1);
+ assertThat(workDuration.hours()).isEqualTo(0);
+ assertThat(workDuration.minutes()).isEqualTo(0);
+ }
+
+ @Test
+ public void convert_to_seconds() throws Exception {
+ assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * 60);
+ assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * 60 * 60);
+ assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toSeconds()).isEqualTo(2 * HOURS_IN_DAY * 60 * 60);
+ }
+
+ @Test
+ public void convert_to_working_days() throws Exception {
+ assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d / 60d / 8d);
+ assertThat(WorkDuration.createFromValueAndUnit(240, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5);
+ assertThat(WorkDuration.createFromValueAndUnit(4, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(0.5);
+ assertThat(WorkDuration.createFromValueAndUnit(8, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(1d);
+ assertThat(WorkDuration.createFromValueAndUnit(16, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d);
+ assertThat(WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY).toWorkingDays()).isEqualTo(2d);
+ }
+
+ @Test
+ public void convert_to_working_long() throws Exception {
+ 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() throws Exception {
+ // 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);
+ assertThat(result.minutes()).isEqualTo(0);
+ 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()).isEqualTo(0);
+ assertThat(result.hours()).isEqualTo(1);
+ assertThat(result.minutes()).isEqualTo(10);
+ assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY);
+
+ // 10 m + 20m = 30m
+ assertThat(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY).add(
+ WorkDuration.createFromValueAndUnit(20, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY)
+ ).minutes()).isEqualTo(30);
+ }
+
+ @Test
+ public void subtract() throws Exception {
+ // 1d 1h - 5h = 4h
+ WorkDuration result = WorkDuration.create(1, 1, 0, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY));
+ assertThat(result.days()).isEqualTo(0);
+ assertThat(result.hours()).isEqualTo(4);
+ assertThat(result.minutes()).isEqualTo(0);
+ assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY);
+
+ // 1h 10m - 30m = 40m
+ result = WorkDuration.create(0, 1, 10, HOURS_IN_DAY).subtract(WorkDuration.createFromValueAndUnit(30, WorkDuration.UNIT.MINUTES, HOURS_IN_DAY));
+ assertThat(result.days()).isEqualTo(0);
+ assertThat(result.hours()).isEqualTo(0);
+ assertThat(result.minutes()).isEqualTo(40);
+ 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);
+ }
+
+ @Test
+ public void multiply() throws Exception {
+ // 5h * 2 = 1d 2h
+ WorkDuration result = WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.HOURS, HOURS_IN_DAY).multiply(2);
+ assertThat(result.days()).isEqualTo(1);
+ assertThat(result.hours()).isEqualTo(2);
+ assertThat(result.minutes()).isEqualTo(0);
+ assertThat(result.hoursInDay()).isEqualTo(HOURS_IN_DAY);
+ }
+}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkUnitTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkUnitTest.java
index c77e0b8bbf6..108f7aa57c2 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkUnitTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WorkUnitTest.java
@@ -36,10 +36,18 @@ public class WorkUnitTest {
@Test
public void create_default() throws Exception {
WorkUnit workUnit = WorkUnit.create();
+ assertThat(workUnit.getUnit()).isEqualTo("d");
assertThat(workUnit.getValue()).isEqualTo(0.0);
}
@Test
+ public void test_equals() throws Exception {
+ assertThat(WorkUnit.create(2.0, "mn")).isEqualTo(WorkUnit.create(2.0, "mn"));
+ assertThat(WorkUnit.create(3.0, "mn")).isNotEqualTo(WorkUnit.create(2.0, "mn"));
+ assertThat(WorkUnit.create(2.0, "h")).isNotEqualTo(WorkUnit.create(2.0, "mn"));
+ }
+
+ @Test
public void fail_with_bad_unit() throws Exception {
try {
WorkUnit.create(2.0, "z");
@@ -57,49 +65,4 @@ public class WorkUnitTest {
}
}
- @Test
- public void from_long_on_simple_values() {
- checkTimes(WorkUnit.fromLong(1L), 0, 0, 1);
- checkTimes(WorkUnit.fromLong(100L), 0, 1, 0);
- checkTimes(WorkUnit.fromLong(10000L), 1, 0, 0);
- }
-
- @Test
- public void from_long_on_complex_values() {
- checkTimes(WorkUnit.fromLong(10101L), 1, 1, 1);
- checkTimes(WorkUnit.fromLong(101L), 0, 1, 1);
- checkTimes(WorkUnit.fromLong(10001L), 1, 0, 1);
- checkTimes(WorkUnit.fromLong(10100L), 1, 1, 0);
-
- checkTimes(WorkUnit.fromLong(112233L), 11, 22, 33);
- }
-
- @Test
- public void to_long() {
- assertThat(new WorkUnit.Builder().setDays(1).setHours(1).setMinutes(1).build().toLong()).isEqualTo(10101L);
- }
-
- @Test
- public void test_equals_and_hashCode() throws Exception {
- WorkUnit oneMinute = WorkUnit.fromLong(1L);
- WorkUnit oneHours = WorkUnit.fromLong(100L);
- WorkUnit oneDay = WorkUnit.fromLong(10000L);
-
- assertThat(oneMinute).isEqualTo(oneMinute);
- assertThat(oneMinute).isEqualTo(WorkUnit.fromLong(1L));
- assertThat(oneHours).isEqualTo(WorkUnit.fromLong(100L));
- assertThat(oneDay).isEqualTo(WorkUnit.fromLong(10000L));
-
- assertThat(oneMinute).isNotEqualTo(oneHours);
- assertThat(oneHours).isNotEqualTo(oneDay);
-
- assertThat(oneMinute.hashCode()).isEqualTo(oneMinute.hashCode());
- }
-
- private void checkTimes(WorkUnit technicalDebt, int expectedDays, int expectedHours, int expectedMinutes) {
- assertThat(technicalDebt.days()).isEqualTo(expectedDays);
- assertThat(technicalDebt.hours()).isEqualTo(expectedHours);
- assertThat(technicalDebt.minutes()).isEqualTo(expectedMinutes);
- }
-
}