aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-10-04 09:34:36 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-10-04 09:34:36 +0200
commit69363f7a5f50722bc41c0216c020a0fd38c7d5e1 (patch)
treef5c7c96987107e23ff6843075a52927ee749c11b /sonar-core
parent7564459620c70d2d620bf2d2a908b71bf3c0214f (diff)
downloadsonarqube-69363f7a5f50722bc41c0216c020a0fd38c7d5e1.tar.gz
sonarqube-69363f7a5f50722bc41c0216c020a0fd38c7d5e1.zip
SONAR-4716 Display the remediation cost of each issue
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/technicaldebt/RemediationCostTimeUnit.java47
-rw-r--r--sonar-core/src/test/java/org/sonar/core/technicaldebt/RemediationCostTimeUnitTest.java26
2 files changed, 12 insertions, 61 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/RemediationCostTimeUnit.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/RemediationCostTimeUnit.java
index ae7d50ed9a7..67ae89e0159 100644
--- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/RemediationCostTimeUnit.java
+++ b/sonar-core/src/main/java/org/sonar/core/technicaldebt/RemediationCostTimeUnit.java
@@ -19,15 +19,11 @@
*/
package org.sonar.core.technicaldebt;
-import javax.annotation.CheckForNull;
-
-import java.util.concurrent.TimeUnit;
-
public class RemediationCostTimeUnit {
- private TimeUnitValue days;
- private TimeUnitValue hours;
- private TimeUnitValue minutes;
+ private long days;
+ private long hours;
+ private long minutes;
private static final int ONE_HOUR_IN_MINUTE = 60;
@@ -35,58 +31,33 @@ public class RemediationCostTimeUnit {
int oneWorkingDay = hoursInDay * ONE_HOUR_IN_MINUTE;
if (input >= oneWorkingDay) {
long nbDays = input / oneWorkingDay;
- this.days = new TimeUnitValue(nbDays, TimeUnit.DAYS);
+ this.days = nbDays;
input = input - (nbDays * oneWorkingDay);
- } else {
- this.days = new TimeUnitValue(0L, TimeUnit.DAYS);
}
if (input >= ONE_HOUR_IN_MINUTE) {
long nbHours = input / ONE_HOUR_IN_MINUTE;
- this.hours = new TimeUnitValue(nbHours, TimeUnit.HOURS);
+ this.hours = nbHours;
input = input - (nbHours * ONE_HOUR_IN_MINUTE);
- } else {
- this.hours = new TimeUnitValue(0L, TimeUnit.HOURS);
}
- this.minutes = new TimeUnitValue(input, TimeUnit.MINUTES);
+ this.minutes = input;
}
public static RemediationCostTimeUnit of(Long time, int hoursInDay) {
return new RemediationCostTimeUnit(time, hoursInDay);
}
- @CheckForNull
- public TimeUnitValue days() {
+ public long days() {
return days;
}
- @CheckForNull
- public TimeUnitValue hours() {
+ public long hours() {
return hours;
}
- @CheckForNull
- public TimeUnitValue minutes() {
+ public long minutes() {
return minutes;
}
- public static class TimeUnitValue {
-
- private long value;
- private TimeUnit unit;
-
- private TimeUnitValue(long value, TimeUnit unit) {
- this.value = value;
- this.unit = unit;
- }
-
- public long value() {
- return value;
- }
-
- public TimeUnit unit() {
- return unit;
- }
- }
}
diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/RemediationCostTimeUnitTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/RemediationCostTimeUnitTest.java
index c655b69449c..ab611144e6c 100644
--- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/RemediationCostTimeUnitTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/technicaldebt/RemediationCostTimeUnitTest.java
@@ -21,8 +21,6 @@ package org.sonar.core.technicaldebt;
import org.junit.Test;
-import java.util.concurrent.TimeUnit;
-
import static org.fest.assertions.Assertions.assertThat;
public class RemediationCostTimeUnitTest {
@@ -44,27 +42,9 @@ public class RemediationCostTimeUnitTest {
}
private void checkTimes(RemediationCostTimeUnit remediationCostTimeUnit, Long expectedMinutes, Long expectedHours, Long expectedDays ) {
- if (expectedMinutes != null) {
- checkTime(remediationCostTimeUnit.minutes(), expectedMinutes, TimeUnit.MINUTES);
- } else {
- assertThat(remediationCostTimeUnit.minutes().value()).isEqualTo(0L);
- }
- if (expectedHours != null) {
- checkTime(remediationCostTimeUnit.hours(), expectedHours, TimeUnit.HOURS);
- } else {
- assertThat(remediationCostTimeUnit.hours().value()).isEqualTo(0L);
- }
- if (expectedDays != null) {
- checkTime(remediationCostTimeUnit.days(), expectedDays, TimeUnit.DAYS);
- } else {
- assertThat(remediationCostTimeUnit.days().value()).isEqualTo(0L);
- }
- }
-
- private void checkTime(RemediationCostTimeUnit.TimeUnitValue timeUnitValue, Long expectedValue, TimeUnit expectedUnit) {
- assertThat(timeUnitValue.value()).isEqualTo(expectedValue);
- assertThat(timeUnitValue.unit()).isEqualTo(expectedUnit);
+ assertThat(remediationCostTimeUnit.minutes()).isEqualTo(expectedMinutes);
+ assertThat(remediationCostTimeUnit.hours()).isEqualTo(expectedHours);
+ assertThat(remediationCostTimeUnit.days()).isEqualTo(expectedDays);
}
-
}