diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-20 11:40:27 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2014-02-25 18:56:40 +0100 |
commit | d2de9de08f20e690b6b96e866c80cc6f9cf0f9b7 (patch) | |
tree | 2a85bcd21ac08282c64f7092c62422c524106d8b /sonar-batch/src | |
parent | f4b8ffb5c43c2daeb572ff08c3c47978f99ad6af (diff) | |
download | sonarqube-d2de9de08f20e690b6b96e866c80cc6f9cf0f9b7.tar.gz sonarqube-d2de9de08f20e690b6b96e866c80cc6f9cf0f9b7.zip |
SONAR-4996 Update issue changelog debt to seconds (backend + display)
Diffstat (limited to 'sonar-batch/src')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java | 4 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java | 45 |
2 files changed, 21 insertions, 28 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java index 1f683ab06b2..cba4b32807d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java @@ -123,7 +123,7 @@ public class IssueChangelogDebtCalculator implements BatchComponent { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { Long newValue = entry.getValue().newValueLong(); if (newValue != null) { - return workDurationFactory.createFromWorkingLong(newValue); + return workDurationFactory.createFromSeconds(newValue); } } } @@ -136,7 +136,7 @@ public class IssueChangelogDebtCalculator implements BatchComponent { if (entry.getKey().equals(IssueUpdater.TECHNICAL_DEBT)) { Long value = entry.getValue().oldValueLong(); if (value != null) { - return workDurationFactory.createFromWorkingLong(value); + return workDurationFactory.createFromSeconds(value); } } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java index dede3970ef0..5096952aa85 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/debt/IssueChangelogDebtCalculatorTest.java @@ -39,6 +39,7 @@ import static org.fest.assertions.Assertions.assertThat; public class IssueChangelogDebtCalculatorTest { private static final int HOURS_IN_DAY = 8; + IssueChangelogDebtCalculator issueChangelogDebtCalculator; Date rightNow = new Date(); @@ -48,13 +49,9 @@ public class IssueChangelogDebtCalculatorTest { Date fiveDaysAgo = DateUtils.addDays(rightNow, -5); Date fourDaysAgo = DateUtils.addDays(rightNow, -4); - WorkDuration oneDaysDebt = WorkDuration.createFromValueAndUnit(1, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); - WorkDuration twoDaysDebt = WorkDuration.createFromValueAndUnit(2, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); - WorkDuration fiveDaysDebt = WorkDuration.createFromValueAndUnit(5, WorkDuration.UNIT.DAYS, HOURS_IN_DAY); - - Long oneDaysDebtInSec = 1 * HOURS_IN_DAY * 60 * 60L; - Long twoDaysDebtInSec = 2 * HOURS_IN_DAY * 60 * 60L; - Long fiveDaysDebtInSec = 5 * HOURS_IN_DAY * 60 * 60L; + long oneDay = 1 * HOURS_IN_DAY * 60 * 60L; + long twoDays = 2 * HOURS_IN_DAY * 60 * 60L; + long fiveDays = 5 * HOURS_IN_DAY * 60 * 60L; @Before public void setUp() throws Exception { @@ -66,10 +63,10 @@ public class IssueChangelogDebtCalculatorTest { @Test public void calculate_new_technical_debt_with_one_diff_in_changelog() throws Exception { - Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDaysDebtInSec).setChanges( + Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDays).setChanges( newArrayList( // changelog created at is null because it has just been created on the current analysis - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(oneDaysDebt), fromWorkDayDuration(twoDaysDebt)).setCreationDate(null) + new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(null) ) ); @@ -84,10 +81,10 @@ public class IssueChangelogDebtCalculatorTest { @Test public void calculate_new_technical_debt_with_many_diffs_in_changelog() throws Exception { - Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDaysDebtInSec).setChanges( + Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDays).setChanges( newArrayList( - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(twoDaysDebt), fromWorkDayDuration(fiveDaysDebt)).setCreationDate(null), - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(oneDaysDebt), fromWorkDayDuration(twoDaysDebt)).setCreationDate(fourDaysAgo) + new FieldDiffs().setDiff("technicalDebt", twoDays, fiveDays).setCreationDate(null), + new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(fourDaysAgo) ) ); @@ -101,14 +98,14 @@ public class IssueChangelogDebtCalculatorTest { @Test public void changelog_can_be_in_wrong_order() { - Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDaysDebtInSec).setChanges( + Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(fiveDays).setChanges( newArrayList( // 3rd - new FieldDiffs().setDiff("technicalDebt", null, fromWorkDayDuration(oneDaysDebt)).setCreationDate(nineDaysAgo), + new FieldDiffs().setDiff("technicalDebt", null, oneDay).setCreationDate(nineDaysAgo), // 1st - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(twoDaysDebt), fromWorkDayDuration(fiveDaysDebt)).setCreationDate(rightNow), + new FieldDiffs().setDiff("technicalDebt", twoDays, fiveDays).setCreationDate(rightNow), // 2nd - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(oneDaysDebt), fromWorkDayDuration(twoDaysDebt)).setCreationDate(fourDaysAgo) + new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(fourDaysAgo) ) ); @@ -120,9 +117,9 @@ public class IssueChangelogDebtCalculatorTest { @Test public void calculate_new_technical_debt_with_null_date() throws Exception { - Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDaysDebtInSec).setChanges( + Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(twoDays).setChanges( newArrayList( - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(oneDaysDebt), fromWorkDayDuration(twoDaysDebt)).setCreationDate(null) + new FieldDiffs().setDiff("technicalDebt", oneDay, twoDays).setCreationDate(null) ) ); @@ -134,8 +131,8 @@ public class IssueChangelogDebtCalculatorTest { public void calculate_new_technical_debt_when_new_debt_is_null() throws Exception { Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(null).setChanges( newArrayList( - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(oneDaysDebt), null).setCreationDate(null), - new FieldDiffs().setDiff("technicalDebt", null, fromWorkDayDuration(oneDaysDebt)).setCreationDate(nineDaysAgo) + new FieldDiffs().setDiff("technicalDebt", oneDay, null).setCreationDate(null), + new FieldDiffs().setDiff("technicalDebt", null, oneDay).setCreationDate(nineDaysAgo) ) ); @@ -151,17 +148,13 @@ public class IssueChangelogDebtCalculatorTest { @Test public void not_return_negative_debt() { - Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(oneDaysDebtInSec).setChanges( + Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setDebt(oneDay).setChanges( newArrayList( - new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(twoDaysDebt), fromWorkDayDuration(oneDaysDebt)).setCreationDate(null) + new FieldDiffs().setDiff("technicalDebt", twoDays, oneDay).setCreationDate(null) ) ); assertThat(issueChangelogDebtCalculator.calculateNewTechnicalDebt(issue, rightNow)).isNull(); } - private Long fromWorkDayDuration(WorkDuration workDayDuration) { - return workDayDuration.toLong(); - } - } |