aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-17 17:23:54 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-02-17 17:23:54 +0100
commit711a2d8cd685b432760f344907e2e8bf962a2ee0 (patch)
tree9ca7a47d739e95a181c5444d83ee6b8f19c1400f
parentf9cbd4c31377f29e6352d6d1d8337c667fec7e89 (diff)
downloadsonarqube-4.1.2.tar.gz
sonarqube-4.1.2.zip
SONAR-5059 New technical debt can sometime be negative4.1.2
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java5
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java19
2 files changed, 23 insertions, 1 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java
index 641d659c25e..120282f9bdb 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecorator.java
@@ -104,7 +104,10 @@ public final class NewTechnicalDebtDecorator implements Decorator {
if (isAfter(issue.creationDate(), periodDatePlusOneSecond)) {
value += technicalDebtConverter.toDays(currentTechnicalDebt);
} else {
- value += calculateNewTechnicalDebtValueFromChangelog(currentTechnicalDebt, issue, periodDate);
+ double debt = calculateNewTechnicalDebtValueFromChangelog(currentTechnicalDebt, issue, periodDate);
+ if (debt > 0) {
+ value += debt;
+ }
}
}
return value;
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java
index 7880c222538..74301a748f0 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/technicaldebt/NewTechnicalDebtDecoratorTest.java
@@ -328,6 +328,25 @@ public class NewTechnicalDebtDecoratorTest {
verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.NEW_TECHNICAL_DEBT)));
}
+ /**
+ * SONAR-5059
+ */
+ @Test
+ public void not_return_negative_debt() {
+ Issue issue = new DefaultIssue().setKey("A").setCreationDate(tenDaysAgo).setTechnicalDebt(oneDaysDebt).setChanges(
+ newArrayList(
+ // changelog created at is null because it has just been created on the current analysis
+ new FieldDiffs().setDiff("technicalDebt", fromWorkDayDuration(twoDaysDebt), fromWorkDayDuration(oneDaysDebt)).setCreationDate(null)
+ )
+ );
+ when(issuable.issues()).thenReturn(newArrayList(issue));
+
+ decorator.decorate(resource, context);
+
+ // remember : period1 is 5daysAgo, period2 is 10daysAgo
+ verify(context).saveMeasure(argThat(new IsVariationMeasure(CoreMetrics.NEW_TECHNICAL_DEBT, 0.0, 0.0)));
+ }
+
private Long fromWorkDayDuration(WorkDayDuration workDayDuration){
return workDayDuration.toLong();
}