]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11103 Missing technical debt when issues on leak period have no debt
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 10 Jan 2019 14:13:33 +0000 (15:13 +0100)
committersonartech <sonartech@sonarsource.com>
Wed, 16 Jan 2019 08:42:58 +0000 (09:42 +0100)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregator.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/NewEffortAggregatorTest.java

index bdcf742fc2d0d56b933abfc4e5e285d8727f6d24..b342e51ddbbb6be02e0f4f188b3526cb595003b3 100644 (file)
@@ -24,13 +24,13 @@ import java.util.HashMap;
 import java.util.Map;
 import org.sonar.api.measures.CoreMetrics;
 import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.core.issue.DefaultIssue;
 import org.sonar.ce.task.projectanalysis.measure.Measure;
 import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
 import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
 import org.sonar.ce.task.projectanalysis.period.Period;
 import org.sonar.ce.task.projectanalysis.period.PeriodHolder;
+import org.sonar.core.issue.DefaultIssue;
 
 import static org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_REMEDIATION_EFFORT_KEY;
 import static org.sonar.api.measures.CoreMetrics.NEW_SECURITY_REMEDIATION_EFFORT_KEY;
@@ -85,16 +85,17 @@ public class NewEffortAggregator extends IssueVisitor {
 
   @Override
   public void afterComponent(Component component) {
-    computeMeasure(component, newMaintainabilityEffortMetric, counter.maintainabilitySum);
-    computeMeasure(component, newReliabilityEffortMetric, counter.reliabilitySum);
-    computeMeasure(component, newSecurityEffortMetric, counter.securitySum);
+    if (periodHolder.hasPeriod()) {
+      computeMeasure(component, newMaintainabilityEffortMetric, counter.maintainabilitySum);
+      computeMeasure(component, newReliabilityEffortMetric, counter.reliabilitySum);
+      computeMeasure(component, newSecurityEffortMetric, counter.securitySum);
+    }
     counter = null;
   }
 
   private void computeMeasure(Component component, Metric metric, EffortSum effortSum) {
-    if (!effortSum.isEmpty) {
-      measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(effortSum.newEffort).createNoValue());
-    }
+    double variation = effortSum.isEmpty ? 0.0 : effortSum.newEffort;
+    measureRepository.add(component, metric, Measure.newMeasureBuilder().setVariation(variation).createNoValue());
   }
 
   private static class NewEffortCounter {
index c2c43d66f212ca871b00d898b0d4b6a6020bea4e..272fc1bd249fb351036f5e224979f8ddab682d07 100644 (file)
@@ -124,6 +124,7 @@ public class NewEffortAggregatorTest {
     DefaultIssue unresolved1 = newBugIssue(10L);
     DefaultIssue old1 = oldBugIssue(100L);
     DefaultIssue unresolved2 = newBugIssue(30L);
+
     DefaultIssue old2 = oldBugIssue(300L);
     DefaultIssue unresolvedWithoutDebt = newBugIssueWithoutEffort();
     DefaultIssue resolved = newBugIssue(50L).setResolution(RESOLUTION_FIXED);
@@ -264,9 +265,22 @@ public class NewEffortAggregatorTest {
     assertThat(measureRepository.getRawMeasures(FILE)).isEmpty();
   }
 
+  @Test
+  public void should_have_empty_measures_if_no_issues() {
+    periodsHolder.setPeriod(PERIOD);
+
+    underTest.beforeComponent(FILE);
+    underTest.afterComponent(FILE);
+
+    assertVariation(FILE, NEW_TECHNICAL_DEBT_KEY, 0);
+    assertVariation(FILE, NEW_RELIABILITY_REMEDIATION_EFFORT_KEY, 0);
+    assertVariation(FILE, NEW_SECURITY_REMEDIATION_EFFORT_KEY, 0);
+  }
+
   private void assertVariation(Component component, String metricKey, int variation) {
     Measure newMeasure = measureRepository.getRawMeasure(component, metricRepository.getByKey(metricKey)).get();
     assertThat(newMeasure.getVariation()).isEqualTo(variation);
+    assertThat(newMeasure.getValueType()).isEqualTo(Measure.ValueType.NO_VALUE);
   }
 
   private static DefaultIssue newCodeSmellIssue(long effort) {