]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 add Issuable#resolvedIssues()
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 21:59:29 +0000 (23:59 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 30 May 2013 21:59:29 +0000 (23:59 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountFalsePositivesDecorator.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountFalsePositivesDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/CountUnresolvedIssuesDecoratorTest.java
sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
sonar-plugin-api/src/main/java/org/sonar/api/issue/Issuable.java

index 0d16aa179d59de3abf5984e64be38fbb66348e8e..3afac003d1f3431822cdb9c44f2fb31b110a4968 100644 (file)
@@ -56,7 +56,7 @@ public class CountFalsePositivesDecorator implements Decorator {
     Issuable issuable = perspectives.as(Issuable.class, resource);
     if (issuable != null) {
       int falsePositives = 0;
-      for (Issue issue : issuable.issues()) {
+      for (Issue issue : issuable.resolvedIssues()) {
         if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) {
           falsePositives++;
         }
index f8495296c027efd08992bf07e730fc6e7f572ab7..643bb8d90416ffb2855180c32fd48e984660d600 100644 (file)
@@ -89,7 +89,7 @@ public class CountUnresolvedIssuesDecorator implements Decorator {
   public void decorate(Resource resource, DecoratorContext context) {
     Issuable issuable = perspectives.as(Issuable.class, resource);
     if (issuable != null) {
-      Collection<Issue> issues = issuable.unresolvedIssues();
+      Collection<Issue> issues = issuable.issues();
       boolean shouldSaveNewMetrics = shouldSaveNewMetrics(context);
 
       Multiset<RulePriority> severityBag = HashMultiset.create();
index 714c8aced26d8d5882b7291982c2bb65a716e352..245987ae4658db49be98966b27e6c298dc3f9d72 100644 (file)
@@ -44,14 +44,14 @@ public class CountFalsePositivesDecoratorTest {
   @Test
   public void should_count_false_positives() {
     DefaultIssue falsePositive = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
-      .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_OPEN);
-    DefaultIssue open = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
-      .setResolution(null).setStatus(Issue.STATUS_OPEN);
+      .setResolution(Issue.RESOLUTION_FALSE_POSITIVE).setStatus(Issue.STATUS_RESOLVED);
+    DefaultIssue fixed = new DefaultIssue().setRuleKey(RuleKey.parse("squid:AvoidCycles"))
+      .setResolution(Issue.RESOLUTION_FIXED).setStatus(Issue.STATUS_RESOLVED);
 
     File file = new File("foo.c");
     Issuable issuable = mock(Issuable.class);
     when(perspectives.as(Issuable.class, file)).thenReturn(issuable);
-    when(issuable.issues()).thenReturn(Arrays.<Issue>asList(falsePositive, open));
+    when(issuable.resolvedIssues()).thenReturn(Arrays.<Issue>asList(falsePositive, fixed));
 
     DecoratorContext context = mock(DecoratorContext.class);
     decorator.decorate(file, context);
index 6ea2df98b522c08240dde67baedc68588ae4de9b..fe1f9a7c7ac4b94b02043802e65e6e33fed04a8d 100644 (file)
@@ -116,7 +116,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_count_issues() {
     when(resource.getScope()).thenReturn(Scopes.PROJECT);
-    when(issuable.unresolvedIssues()).thenReturn(createIssues());
+    when(issuable.issues()).thenReturn(createissues());
     when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
 
     decorator.decorate(resource, context);
@@ -141,7 +141,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_not_count_issues_if_measure_already_exists() {
     when(resource.getScope()).thenReturn(Scopes.PROJECT);
-    when(issuable.unresolvedIssues()).thenReturn(createIssues());
+    when(issuable.issues()).thenReturn(createissues());
     when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
     when(context.getMeasure(CoreMetrics.VIOLATIONS)).thenReturn(new Measure(CoreMetrics.VIOLATIONS, 3000.0));
     when(context.getMeasure(CoreMetrics.MAJOR_VIOLATIONS)).thenReturn(new Measure(CoreMetrics.MAJOR_VIOLATIONS, 500.0));
@@ -156,7 +156,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_save_zero_on_projects() {
     when(resource.getScope()).thenReturn(Scopes.PROJECT);
-    when(issuable.unresolvedIssues()).thenReturn(Lists.<Issue>newArrayList());
+    when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
     when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
 
     decorator.decorate(resource, context);
@@ -167,7 +167,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_save_zero_on_directories() {
     when(resource.getScope()).thenReturn(Scopes.DIRECTORY);
-    when(issuable.unresolvedIssues()).thenReturn(Lists.<Issue>newArrayList());
+    when(issuable.issues()).thenReturn(Lists.<Issue>newArrayList());
     when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
 
     decorator.decorate(resource, context);
@@ -178,7 +178,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_count_issues_by_severity() {
     when(resource.getScope()).thenReturn(Scopes.PROJECT);
-    when(issuable.unresolvedIssues()).thenReturn(createIssues());
+    when(issuable.issues()).thenReturn(createissues());
     when(context.getChildrenMeasures(any(MeasuresFilter.class))).thenReturn(Collections.<Measure>emptyList());
 
     decorator.decorate(resource, context);
@@ -196,7 +196,7 @@ public class CountUnresolvedIssuesDecoratorTest {
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
     issues.add(new DefaultIssue().setRuleKey(ruleA2.ruleKey()).setSeverity(RulePriority.MAJOR.name()));
-    when(issuable.unresolvedIssues()).thenReturn(issues);
+    when(issuable.issues()).thenReturn(issues);
 
     decorator.decorate(resource, context);
 
@@ -211,7 +211,7 @@ public class CountUnresolvedIssuesDecoratorTest {
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.CRITICAL.name()));
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(RulePriority.MINOR.name()));
-    when(issuable.unresolvedIssues()).thenReturn(issues);
+    when(issuable.issues()).thenReturn(issues);
 
     decorator.decorate(resource, context);
 
@@ -232,7 +232,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   public void should_clear_cache_after_execution() {
     Issue issue1 = new DefaultIssue().setRuleKey(RuleKey.of(ruleA1.getRepositoryKey(), ruleA1.getKey())).setSeverity(RulePriority.CRITICAL.name()).setCreationDate(rightNow);
     Issue issue2 = new DefaultIssue().setRuleKey(RuleKey.of(ruleA2.getRepositoryKey(), ruleA2.getKey())).setSeverity(RulePriority.CRITICAL.name()).setCreationDate(rightNow);
-    when(issuable.unresolvedIssues()).thenReturn(newArrayList(issue1)).thenReturn(newArrayList(issue2));
+    when(issuable.issues()).thenReturn(newArrayList(issue1)).thenReturn(newArrayList(issue2));
 
     decorator.decorate(resource, context);
     decorator.decorate(resource, context);
@@ -243,7 +243,7 @@ public class CountUnresolvedIssuesDecoratorTest {
 
   @Test
   public void should_save_severity_new_issues() {
-    when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+    when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
 
     decorator.decorate(resource, context);
 
@@ -257,7 +257,7 @@ public class CountUnresolvedIssuesDecoratorTest {
 
   @Test
   public void should_save_rule_new_issues() {
-    when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+    when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
 
     decorator.decorate(resource, context);
 
@@ -270,7 +270,7 @@ public class CountUnresolvedIssuesDecoratorTest {
   @Test
   public void should_not_save_new_issues_if_measure_already_computed() {
     when(context.getMeasure(CoreMetrics.NEW_VIOLATIONS)).thenReturn(new Measure());
-    when(issuable.unresolvedIssues()).thenReturn(createIssuesForNewMetrics());
+    when(issuable.issues()).thenReturn(createIssuesForNewMetrics());
 
     decorator.decorate(resource, context);
 
@@ -282,7 +282,7 @@ public class CountUnresolvedIssuesDecoratorTest {
     verify(context, never()).saveMeasure(argThat(new IsMetricMeasure(CoreMetrics.NEW_CRITICAL_VIOLATIONS)));
   }
 
-  List<Issue> createIssues() {
+  List<Issue> createissues() {
     List<Issue> issues = newArrayList();
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(Severity.CRITICAL).setStatus(Issue.STATUS_OPEN));
     issues.add(new DefaultIssue().setRuleKey(ruleA1.ruleKey()).setSeverity(Severity.CRITICAL).setStatus(Issue.STATUS_REOPENED));
index 475afd38f71b0875d905c66d28dba16513a7c155..bcdd61f48477ad60449b2b2b0d062f4fcec1f473 100644 (file)
@@ -55,14 +55,19 @@ public class DefaultIssuable implements Issuable {
 
   @SuppressWarnings("unchecked")
   @Override
-  public List<Issue> issues() {
-    Iterable<DefaultIssue> elements = cache.byComponent(component.key());
-    return Lists.<Issue>newArrayList(elements);
+  public List<Issue> resolvedIssues() {
+    List<Issue> result = Lists.newArrayList();
+    for (DefaultIssue issue : cache.byComponent(component.key())) {
+      if (issue.resolution()!=null) {
+        result.add(issue);
+      }
+    }
+    return result;
   }
 
   @SuppressWarnings("unchecked")
   @Override
-  public List<Issue> unresolvedIssues() {
+  public List<Issue> issues() {
     List<Issue> result = Lists.newArrayList();
     for (DefaultIssue issue : cache.byComponent(component.key())) {
       if (issue.resolution()==null) {
index 364aa4df2075abad0166056fc5578079015dad64..15d362324e03a526329a2533e47c52e213122a43 100644 (file)
@@ -38,7 +38,7 @@ public class DefaultIssuableTest {
   Component component = mock(Component.class);
 
   @Test
-  public void test_unresolvedIssues() throws Exception {
+  public void test_unresolved_issues() throws Exception {
     when(component.key()).thenReturn("struts:org.apache.Action");
     DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE);
     DefaultIssue unresolved = new DefaultIssue();
@@ -46,12 +46,12 @@ public class DefaultIssuableTest {
 
     DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache);
 
-    List<Issue> issues = perspective.unresolvedIssues();
+    List<Issue> issues = perspective.issues();
     assertThat(issues).containsOnly(unresolved);
   }
 
   @Test
-  public void test_issues() throws Exception {
+  public void test_resolved_issues() throws Exception {
     when(component.key()).thenReturn("struts:org.apache.Action");
     DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE);
     DefaultIssue unresolved = new DefaultIssue();
@@ -59,7 +59,7 @@ public class DefaultIssuableTest {
 
     DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache);
 
-    List<Issue> issues = perspective.issues();
-    assertThat(issues).containsOnly(unresolved, resolved);
+    List<Issue> issues = perspective.resolvedIssues();
+    assertThat(issues).containsOnly(resolved);
   }
 }
index d5cc74389c98ab4d6a98f95b2d95db9ddc0dd783..7af6bef3bf87141d1b238e128a7be3f2f0ae99f4 100644 (file)
@@ -59,10 +59,10 @@ public interface Issuable extends Perspective {
   /**
    * The issues that are not resolved (=open). They include the manual issues reported by end-users.
    */
-  List<Issue> unresolvedIssues();
+  List<Issue> issues();
 
   /**
-   * All issues, even the issues that are resolved or closed during this analysis.
+   * The issues marked as resolved during this scan.
    */
-  List<Issue> issues();
+  List<Issue> resolvedIssues();
 }