diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-30 18:26:02 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-30 18:26:02 +0200 |
commit | 997785024dffbc84f9f460a8abe7839317a6d756 (patch) | |
tree | 1d52a34faa1597a6ff932af89fbd648db52a2a0e /sonar-batch | |
parent | c35a38ea003ecfabccd079a0060d4b4b0e221b3c (diff) | |
download | sonarqube-997785024dffbc84f9f460a8abe7839317a6d756.tar.gz sonarqube-997785024dffbc84f9f460a8abe7839317a6d756.zip |
Add Issuable#unresolvedIssues()
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java | 12 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java | 65 |
2 files changed, 77 insertions, 0 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java index 06a0c3df42d..475afd38f71 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java @@ -60,6 +60,18 @@ public class DefaultIssuable implements Issuable { return Lists.<Issue>newArrayList(elements); } + @SuppressWarnings("unchecked") + @Override + public List<Issue> unresolvedIssues() { + List<Issue> result = Lists.newArrayList(); + for (DefaultIssue issue : cache.byComponent(component.key())) { + if (issue.resolution()==null) { + result.add(issue); + } + } + return result; + } + @Override public Component component() { return component; diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java new file mode 100644 index 00000000000..364aa4df207 --- /dev/null +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java @@ -0,0 +1,65 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2013 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.batch.issue; + +import org.junit.Test; +import org.sonar.api.component.Component; +import org.sonar.api.issue.Issue; +import org.sonar.core.issue.DefaultIssue; + +import java.util.Arrays; +import java.util.List; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class DefaultIssuableTest { + + ScanIssues scanIssues = mock(ScanIssues.class); + IssueCache cache = mock(IssueCache.class); + Component component = mock(Component.class); + + @Test + public void test_unresolvedIssues() throws Exception { + when(component.key()).thenReturn("struts:org.apache.Action"); + DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE); + DefaultIssue unresolved = new DefaultIssue(); + when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved)); + + DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache); + + List<Issue> issues = perspective.unresolvedIssues(); + assertThat(issues).containsOnly(unresolved); + } + + @Test + public void test_issues() throws Exception { + when(component.key()).thenReturn("struts:org.apache.Action"); + DefaultIssue resolved = new DefaultIssue().setResolution(Issue.RESOLUTION_FALSE_POSITIVE); + DefaultIssue unresolved = new DefaultIssue(); + when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved)); + + DefaultIssuable perspective = new DefaultIssuable(component, scanIssues, cache); + + List<Issue> issues = perspective.issues(); + assertThat(issues).containsOnly(unresolved, resolved); + } +} |