diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-10-14 11:20:02 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-10-14 11:20:12 +0200 |
commit | ef96d186dcf91b1651a2a607625986dceb7badaf (patch) | |
tree | 6a2ed5d657d71f6e0ce75187434bf30b4cbf0e4e /plugins | |
parent | 10ed74f4dd11c62a30c64207e3dac76214d5a41b (diff) | |
download | sonarqube-ef96d186dcf91b1651a2a607625986dceb7badaf.tar.gz sonarqube-ef96d186dcf91b1651a2a607625986dceb7badaf.zip |
SONAR-4716 Fix issue when setting technical debt on existing issues
Diffstat (limited to 'plugins')
2 files changed, 48 insertions, 11 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java index d8c9bd6936a..0d668bc8d54 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java @@ -66,13 +66,13 @@ public class IssueTrackingDecorator implements Decorator { private final RuleFinder ruleFinder; public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking, - LastSnapshots lastSnapshots, SonarIndex index, - IssueHandlers handlers, IssueWorkflow workflow, - IssueUpdater updater, - Project project, - ResourcePerspectives perspectives, - RulesProfile rulesProfile, - RuleFinder ruleFinder) { + LastSnapshots lastSnapshots, SonarIndex index, + IssueHandlers handlers, IssueWorkflow workflow, + IssueUpdater updater, + Project project, + ResourcePerspectives perspectives, + RulesProfile rulesProfile, + RuleFinder ruleFinder) { this.issueCache = issueCache; this.initialOpenIssues = initialOpenIssues; this.tracking = tracking; @@ -131,7 +131,8 @@ public class IssueTrackingDecorator implements Decorator { } } - private void mergeMatched(IssueTrackingResult result) { + @VisibleForTesting + protected void mergeMatched(IssueTrackingResult result) { for (DefaultIssue issue : result.matched()) { IssueDto ref = result.matching(issue); @@ -168,9 +169,8 @@ public class IssueTrackingDecorator implements Decorator { updater.setPastMessage(issue, ref.getMessage(), changeContext); updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext); Long technicalDebt = ref.getTechnicalDebt(); - if (technicalDebt != null) { - updater.setPastTechnicalDebt(issue, TechnicalDebt.fromLong(technicalDebt), changeContext); - } + TechnicalDebt previousTechnicalDebt = technicalDebt != null ? TechnicalDebt.fromLong(technicalDebt) : null; + updater.setPastTechnicalDebt(issue, previousTechnicalDebt, changeContext); } } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java index 5b1d0b0bbc4..c01199f3c61 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java @@ -36,6 +36,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; +import org.sonar.api.technicaldebt.TechnicalDebt; import org.sonar.batch.issue.IssueCache; import org.sonar.batch.scan.LastSnapshots; import org.sonar.core.issue.IssueUpdater; @@ -49,6 +50,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyCollection; @@ -56,6 +58,7 @@ import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.*; +import static org.mockito.Mockito.anyString; public class IssueTrackingDecoratorTest extends AbstractDaoTestCase { @@ -500,4 +503,38 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase { } })); } + + @Test + public void merge_matched_issue() throws Exception { + IssueDto previousIssue = new IssueDto().setKee("ABCDE").setResolution(null).setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle") + .setLine(10).setSeverity("MAJOR").setMessage("Message").setEffortToFix(1.5).setTechnicalDebt(1L); + DefaultIssue issue = new DefaultIssue(); + + IssueTrackingResult trackingResult = mock(IssueTrackingResult.class); + when(trackingResult.matched()).thenReturn(newArrayList(issue)); + when(trackingResult.matching(eq(issue))).thenReturn(previousIssue); + decorator.mergeMatched(trackingResult); + + verify(updater).setPastSeverity(eq(issue), eq("MAJOR"), any(IssueChangeContext.class)); + verify(updater).setPastLine(eq(issue), eq(10)); + verify(updater).setPastMessage(eq(issue), eq("Message"), any(IssueChangeContext.class)); + verify(updater).setPastEffortToFix(eq(issue), eq(1.5), any(IssueChangeContext.class)); + verify(updater).setPastTechnicalDebt(eq(issue), eq(TechnicalDebt.of(1, 0, 0)), any(IssueChangeContext.class)); + } + + @Test + public void merge_matched_issue_on_manual_severity() throws Exception { + IssueDto previousIssue = new IssueDto().setKee("ABCDE").setResolution(null).setStatus("OPEN").setRuleKey_unit_test_only("squid", "AvoidCycle") + .setLine(10).setManualSeverity(true).setSeverity("MAJOR").setMessage("Message").setEffortToFix(1.5).setTechnicalDebt(1L); + DefaultIssue issue = new DefaultIssue(); + + IssueTrackingResult trackingResult = mock(IssueTrackingResult.class); + when(trackingResult.matched()).thenReturn(newArrayList(issue)); + when(trackingResult.matching(eq(issue))).thenReturn(previousIssue); + decorator.mergeMatched(trackingResult); + + assertThat(issue.manualSeverity()).isTrue(); + assertThat(issue.severity()).isEqualTo("MAJOR"); + verify(updater, never()).setPastSeverity(eq(issue), anyString(), any(IssueChangeContext.class)); + } } |