diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-19 18:26:02 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-25 18:53:51 +0100 |
commit | 0e4fedebee2ab25fcdf8e90104fae836aa460dec (patch) | |
tree | a52bc1c770d31613cad7af3cc6f02845cfab9cae /sonar-core/src | |
parent | c8de42f296fedafaadd5a25cac66bbea234a285e (diff) | |
download | sonarqube-0e4fedebee2ab25fcdf8e90104fae836aa460dec.tar.gz sonarqube-0e4fedebee2ab25fcdf8e90104fae836aa460dec.zip |
SONAR-4996 Update issue debt to seconds (backend + display)
Diffstat (limited to 'sonar-core/src')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java | 11 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java | 32 |
2 files changed, 10 insertions, 33 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java index 4d39dccb915..754ad01f50b 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueUpdater.java @@ -29,7 +29,6 @@ import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.DefaultIssueComment; import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.user.User; -import org.sonar.api.utils.WorkDurationFactory; import javax.annotation.Nullable; import java.util.Calendar; @@ -49,12 +48,6 @@ public class IssueUpdater implements BatchComponent, ServerComponent { public static final String ACTION_PLAN = "actionPlan"; public static final String TECHNICAL_DEBT = "technicalDebt"; - private final WorkDurationFactory workDurationFactory; - - public IssueUpdater(WorkDurationFactory workDurationFactory) { - this.workDurationFactory = workDurationFactory; - } - public boolean setSeverity(DefaultIssue issue, String severity, IssueChangeContext context) { if (issue.manualSeverity()) { throw new IllegalStateException("Severity can't be changed"); @@ -209,9 +202,7 @@ public class IssueUpdater implements BatchComponent, ServerComponent { Long oldValue = issue.debt(); if (!Objects.equal(value, oldValue)) { issue.setDebt(value); - Long oldValueInLong = oldValue != null ? workDurationFactory.createFromSeconds(oldValue).toLong() : null; - Long newValueInLong = value != null ? workDurationFactory.createFromSeconds(value).toLong() : null; - issue.setFieldChange(context, TECHNICAL_DEBT, oldValueInLong, newValueInLong); + issue.setFieldChange(context, TECHNICAL_DEBT, oldValue, value); issue.setUpdateDate(context.date()); issue.setChanged(true); return true; diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java index e1263611418..67666485d44 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueUpdaterTest.java @@ -19,17 +19,12 @@ */ package org.sonar.core.issue; -import org.junit.Before; import org.junit.Test; -import org.sonar.api.CoreProperties; -import org.sonar.api.config.Settings; import org.sonar.api.issue.ActionPlan; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.issue.internal.IssueChangeContext; import org.sonar.api.user.User; -import org.sonar.api.utils.WorkDuration; -import org.sonar.api.utils.WorkDurationFactory; import org.sonar.core.user.DefaultUser; import java.util.Date; @@ -39,19 +34,10 @@ import static org.sonar.core.issue.IssueUpdater.*; public class IssueUpdaterTest { + IssueUpdater updater = new IssueUpdater(); DefaultIssue issue = new DefaultIssue(); IssueChangeContext context = IssueChangeContext.createUser(new Date(), "emmerik"); - IssueUpdater updater; - - @Before - public void setUp() throws Exception { - Settings settings = new Settings(); - settings.setProperty(CoreProperties.HOURS_IN_DAY, 8); - - updater = new IssueUpdater(new WorkDurationFactory(settings)); - } - @Test public void assign() throws Exception { User user = new DefaultUser().setLogin("emmerik").setName("Emmerik"); @@ -379,8 +365,8 @@ public class IssueUpdaterTest { @Test public void set_past_technical_debt() throws Exception { - long newDebt = 15 * 8 * 60 * 60; - long previousDebt = 10 * 8 * 60 * 60; + long newDebt = 15; + long previousDebt = 10; issue.setDebt(newDebt); boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); assertThat(updated).isTrue(); @@ -388,13 +374,13 @@ public class IssueUpdaterTest { assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); - assertThat(diff.oldValue()).isEqualTo(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.DAYS, 8).toLong()); - assertThat(diff.newValue()).isEqualTo(WorkDuration.createFromValueAndUnit(15, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.oldValue()).isEqualTo(previousDebt); + assertThat(diff.newValue()).isEqualTo(newDebt); } @Test public void set_past_technical_debt_without_previous_value() throws Exception { - long newDebt = 15 * 8 * 60 * 60; + long newDebt = 15; issue.setDebt(newDebt); boolean updated = updater.setPastTechnicalDebt(issue, null, context); assertThat(updated).isTrue(); @@ -403,20 +389,20 @@ public class IssueUpdaterTest { FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); assertThat(diff.oldValue()).isNull(); - assertThat(diff.newValue()).isEqualTo(WorkDuration.createFromValueAndUnit(15, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.newValue()).isEqualTo(newDebt); } @Test public void set_past_technical_debt_with_null_new_value() throws Exception { issue.setDebt(null); - long previousDebt = 10 * 8 * 60 * 60; + long previousDebt = 10; boolean updated = updater.setPastTechnicalDebt(issue, previousDebt, context); assertThat(updated).isTrue(); assertThat(issue.debt()).isNull(); assertThat(issue.mustSendNotifications()).isFalse(); FieldDiffs.Diff diff = issue.currentChange().get(TECHNICAL_DEBT); - assertThat(diff.oldValue()).isEqualTo(WorkDuration.createFromValueAndUnit(10, WorkDuration.UNIT.DAYS, 8).toLong()); + assertThat(diff.oldValue()).isEqualTo(previousDebt); assertThat(diff.newValue()).isNull(); } |