aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-10-01 21:56:16 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-10-01 21:56:16 +0200
commitc66ed023d5ef8de630557081b582dbde562eb3ee (patch)
tree40b6becce3d1ca9fcf2cbef1d9c35d6780c18f3d /sonar-batch
parent4887d9c4787f4bb4b15ba232d636df5a78e657a6 (diff)
downloadsonarqube-c66ed023d5ef8de630557081b582dbde562eb3ee.tar.gz
sonarqube-c66ed023d5ef8de630557081b582dbde562eb3ee.zip
SONAR-4716 Add remediation cost when creating issues
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java48
2 files changed, 42 insertions, 12 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 7bef92697a9..a3f695151f0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -26,6 +26,7 @@ import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Violation;
import org.sonar.core.issue.DefaultIssueBuilder;
+import org.sonar.core.technicaldebt.TechnicalDebtCalculator;
import javax.annotation.Nullable;
@@ -38,12 +39,14 @@ public class ModuleIssues {
private final IssueCache cache;
private final Project project;
private final IssueFilters filters;
+ private final TechnicalDebtCalculator technicalDebtCalculator;
- public ModuleIssues(RulesProfile qProfile, IssueCache cache, Project project, IssueFilters filters) {
+ public ModuleIssues(RulesProfile qProfile, IssueCache cache, Project project, IssueFilters filters, TechnicalDebtCalculator technicalDebtCalculator) {
this.qProfile = qProfile;
this.cache = cache;
this.project = project;
this.filters = filters;
+ this.technicalDebtCalculator = technicalDebtCalculator;
}
public boolean initAndAddIssue(DefaultIssue issue) {
@@ -79,6 +82,7 @@ public class ModuleIssues {
if (issue.severity() == null) {
issue.setSeverity(activeRule.getSeverity().name());
}
+ issue.setRemediationCost(technicalDebtCalculator.cost(issue));
if (filters.accept(issue, violation)) {
cache.put(issue);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index 2fc2f8d2543..0097856a211 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -34,6 +34,7 @@ import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.Violation;
+import org.sonar.core.technicaldebt.TechnicalDebtCalculator;
import java.util.Calendar;
import java.util.Date;
@@ -42,10 +43,7 @@ import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class ModuleIssuesTest {
@@ -55,7 +53,8 @@ public class ModuleIssuesTest {
RulesProfile qProfile = mock(RulesProfile.class);
Project project = mock(Project.class);
IssueFilters filters = mock(IssueFilters.class);
- ModuleIssues moduleIssues = new ModuleIssues(qProfile, cache, project, filters);
+ TechnicalDebtCalculator technicalDebtCalculator = mock(TechnicalDebtCalculator.class);
+ ModuleIssues moduleIssues = new ModuleIssues(qProfile, cache, project, filters, technicalDebtCalculator);
@Before
public void setUp() {
@@ -64,7 +63,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_ignore_null_active_rule() throws Exception {
+ public void ignore_null_active_rule() throws Exception {
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(null);
DefaultIssue issue = new DefaultIssue().setRuleKey(SQUID_RULE_KEY);
@@ -75,7 +74,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_ignore_null_rule_of_active_rule() throws Exception {
+ public void ignore_null_rule_of_active_rule() throws Exception {
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(null);
when(qProfile.getActiveRule(anyString(), anyString())).thenReturn(activeRule);
@@ -88,7 +87,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_add_issue_to_cache() throws Exception {
+ public void add_issue_to_cache() throws Exception {
Rule rule = Rule.create("squid", "AvoidCycle");
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
@@ -114,7 +113,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_use_severity_from_active_rule_if_no_severity() throws Exception {
+ public void use_severity_from_active_rule_if_no_severity() throws Exception {
Rule rule = Rule.create("squid", "AvoidCycle");
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
@@ -135,7 +134,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_add_deprecated_violation() throws Exception {
+ public void add_deprecated_violation() throws Exception {
Rule rule = Rule.create("squid", "AvoidCycle");
Resource resource = new JavaFile("org.struts.Action").setEffectiveKey("struts:org.struts.Action");
Violation violation = new Violation(rule, resource);
@@ -164,7 +163,7 @@ public class ModuleIssuesTest {
}
@Test
- public void should_filter_issue() throws Exception {
+ public void filter_issue() throws Exception {
Rule rule = Rule.create("squid", "AvoidCycle");
ActiveRule activeRule = mock(ActiveRule.class);
when(activeRule.getRule()).thenReturn(rule);
@@ -184,4 +183,31 @@ public class ModuleIssuesTest {
verifyZeroInteractions(cache);
}
+ @Test
+ public void set_remediation_cost() throws Exception {
+ Rule rule = Rule.create("squid", "AvoidCycle");
+ ActiveRule activeRule = mock(ActiveRule.class);
+ when(activeRule.getRule()).thenReturn(rule);
+ when(activeRule.getSeverity()).thenReturn(RulePriority.INFO);
+ when(qProfile.getActiveRule("squid", "AvoidCycle")).thenReturn(activeRule);
+
+ Date analysisDate = new Date();
+ when(project.getAnalysisDate()).thenReturn(analysisDate);
+
+
+ DefaultIssue issue = new DefaultIssue()
+ .setKey("ABCDE")
+ .setRuleKey(SQUID_RULE_KEY)
+ .setSeverity(Severity.CRITICAL);
+
+ when(technicalDebtCalculator.cost(issue)).thenReturn(10L);
+ when(filters.accept(issue, null)).thenReturn(true);
+
+ moduleIssues.initAndAddIssue(issue);
+
+ ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class);
+ verify(cache).put(argument.capture());
+ assertThat(argument.getValue().remediationCost()).isEqualTo(10L);
+ }
+
}