diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-07 22:01:59 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-01-07 22:07:30 +0100 |
commit | d3dd88adf13034f9972a5a673280709cca95f935 (patch) | |
tree | ff1caadf8801ad142431b6bd36e77ab19e68bdce /sonar-batch/src/test | |
parent | c698fdc1b308fef1a7af5767e42e6b7e82fb502e (diff) | |
download | sonarqube-d3dd88adf13034f9972a5a673280709cca95f935.tar.gz sonarqube-d3dd88adf13034f9972a5a673280709cca95f935.zip |
SONAR-6014 Drop deprecated violations
Diffstat (limited to 'sonar-batch/src/test')
6 files changed, 18 insertions, 286 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ViolationFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/ViolationFiltersTest.java deleted file mode 100644 index c1449cfb941..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/ViolationFiltersTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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; - -import org.junit.Test; -import org.sonar.api.rules.Violation; -import org.sonar.api.rules.ViolationFilter; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class ViolationFiltersTest { - - @Test - public void doNotFailIfNoFilters() { - ViolationFilters filters = new ViolationFilters(); - assertThat(filters.isIgnored(new Violation(null)), is(false)); - } - - @Test - public void ignoreViolation() { - ViolationFilters filters = new ViolationFilters(new ViolationFilter[]{ - new FakeFilter(false), - new FakeFilter(true), - new FakeFilter(false), - }); - assertThat(filters.isIgnored(new Violation(null)), is(true)); - } - - @Test - public void doNotIgnoreValidViolations() { - ViolationFilters filters = new ViolationFilters(new ViolationFilter[]{ - new FakeFilter(false), - new FakeFilter(false), - new FakeFilter(false), - }); - assertThat(filters.isIgnored(new Violation(null)), is(false)); - } - - private static class FakeFilter implements ViolationFilter { - private boolean ignore; - - private FakeFilter(boolean ignore) { - this.ignore = ignore; - } - - public boolean isIgnored(Violation violation) { - return ignore; - } - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java index 42ca92d27b2..b37474770b9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java @@ -38,18 +38,13 @@ import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Resource; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; -import org.sonar.api.rules.Violation; -import org.sonar.api.violations.ViolationQuery; import org.sonar.batch.ProjectTree; -import org.sonar.batch.issue.DeprecatedViolations; import org.sonar.batch.issue.ModuleIssues; import org.sonar.batch.scan.measure.MeasureCache; import java.io.IOException; -import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; -import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -59,7 +54,6 @@ public class DefaultIndexTest { public TemporaryFolder temp = new TemporaryFolder(); DefaultIndex index = null; - DeprecatedViolations deprecatedViolations; Rule rule; RuleFinder ruleFinder; Project project; @@ -71,14 +65,13 @@ public class DefaultIndexTest { @Before public void createIndex() throws IOException { - deprecatedViolations = mock(DeprecatedViolations.class); MetricFinder metricFinder = mock(MetricFinder.class); when(metricFinder.findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC); ruleFinder = mock(RuleFinder.class); ProjectTree projectTree = mock(ProjectTree.class); ResourceCache resourceCache = new ResourceCache(); - index = new DefaultIndex(resourceCache, null, null, null, projectTree, metricFinder, deprecatedViolations, + index = new DefaultIndex(resourceCache, null, null, null, projectTree, metricFinder, mock(ResourceKeyMigration.class), mock(MeasureCache.class)); @@ -179,85 +172,6 @@ public class DefaultIndexTest { assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc"))).isNull(); } - /** - * See http://jira.codehaus.org/browse/SONAR-2107 - */ - @Test - public void shouldNotFailWhenSavingViolationOnNullRule() { - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create((Rule) null, file); - index.addViolation(violation); - - assertThat(index.getViolations(file)).isEmpty(); - } - - /** - * See https://jira.codehaus.org/browse/SONAR-3583 - */ - @Test - public void should_ignore_violation_on_unknown_rules() { - Rule ruleWithoutID = Rule.create("repoKey", "ruleKey", "Rule"); - - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create(ruleWithoutID, file); - index.addViolation(violation); - - assertThat(index.getViolations(file)).isEmpty(); - } - - @Test - public void should_get_violation() { - Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create(rule, file); - when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); - - index.index(file); - index.addViolation(violation); - - assertThat(index.getViolations(file)).hasSize(1); - } - - @Test - public void should_not_save_violation_if_resource_not_indexed() { - Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create(rule, file); - when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); - - index.addViolation(violation); - - assertThat(index.getViolations(file)).hasSize(0); - } - - @Test - public void should_get_filtered_violation_with_off_switch_mode() { - Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create(rule, file).setSwitchedOff(true); - - when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); - - index.index(file); - index.addViolation(violation); - - assertThat(index.getViolations(ViolationQuery.create().forResource(file).setSwitchMode(ViolationQuery.SwitchMode.OFF))).hasSize(1); - } - - @Test - public void should_get_filtered_violation_with_on_switch_mode() { - Rule rule = Rule.create("repoKey", "ruleKey", "Rule"); - File file = File.create("src/org/foo/Bar.java", "org/foo/Bar.java", null, false); - Violation violation = Violation.create(rule, file).setSwitchedOff(false); - - when(deprecatedViolations.get(anyString())).thenReturn(newArrayList(violation)); - - index.index(file); - index.addViolation(violation); - - assertThat(index.getViolations(ViolationQuery.create().forResource(file).setSwitchMode(ViolationQuery.SwitchMode.ON))).hasSize(1); - } - @Test public void shouldComputePathOfIndexedModules() { assertThat(index.getResource(project).getPath()).isNull(); @@ -266,9 +180,4 @@ public class DefaultIndexTest { assertThat(index.getResource(moduleB1).getPath()).isEqualTo("moduleB1"); } - @Test(expected = IllegalArgumentException.class) - public void testGetViolationsWithQueryWithNoResource() { - index.getViolations(ViolationQuery.create()); - } - } diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java index 33da7d65bed..90eb8fa23ef 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java @@ -37,7 +37,6 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.security.ResourcePermissions; import org.sonar.batch.ProjectTree; -import org.sonar.batch.issue.DeprecatedViolations; import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.core.component.ComponentDto; import org.sonar.core.component.ScanGraph; @@ -223,7 +222,6 @@ public class ResourcePersisterTest extends AbstractDbUnitTestCase { when(projectTree.getProjectDefinition(moduleB1)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1"))); DefaultIndex index = new DefaultIndex(resourceCache, null, null, null, projectTree, mock(MetricFinder.class), - mock(DeprecatedViolations.class), mock(ResourceKeyMigration.class), mock(MeasureCache.class)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java deleted file mode 100644 index b5c7862c740..00000000000 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.issue.internal.DefaultIssue; -import org.sonar.api.resources.Project; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.rule.Severity; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.rules.Violation; -import org.sonar.batch.index.BatchResource; -import org.sonar.batch.index.ResourceCache; - -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 DeprecatedViolationsTest { - - IssueCache issueCache = mock(IssueCache.class); - RuleFinder ruleFinder = mock(RuleFinder.class); - ResourceCache resourceCache = mock(ResourceCache.class); - DeprecatedViolations deprecatedViolations = new DeprecatedViolations(issueCache, ruleFinder, resourceCache); - - @Test - public void test_toViolation() throws Exception { - RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles"); - when(ruleFinder.findByKey(ruleKey)).thenReturn(new Rule("squid", "AvoidCycles")); - when(resourceCache.get("org.apache:struts")).thenReturn(new BatchResource(1, new Project("org.apache:struts"), null)); - - DefaultIssue issue = newIssue(ruleKey); - - Violation violation = deprecatedViolations.toViolation(issue); - assertThat(violation.getLineId()).isEqualTo(42); - assertThat(violation.getSeverity()).isEqualTo(RulePriority.BLOCKER); - assertThat(violation.isManual()).isTrue(); - assertThat(violation.getRule().getRepositoryKey()).isEqualTo("squid"); - assertThat(violation.getRule().getKey()).isEqualTo("AvoidCycles"); - assertThat(violation.getResource()).isNotNull(); - assertThat(violation.isSwitchedOff()).isFalse(); - } - - private DefaultIssue newIssue(RuleKey ruleKey) { - DefaultIssue issue = new DefaultIssue(); - issue.setKey("ABCDE"); - issue.setRuleKey(ruleKey); - issue.setComponentKey("org.apache:struts"); - issue.setLine(42); - issue.setEffortToFix(3.14); - issue.setReporter("leon"); - issue.setSeverity(Severity.BLOCKER); - return issue; - } - - @Test - public void test_get() throws Exception { - RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles"); - when(ruleFinder.findByKey(ruleKey)).thenReturn(new Rule("squid", "AvoidCycles")); - when(resourceCache.get("org.apache:struts")).thenReturn(new BatchResource(1, new Project("org.apache:struts"), null)); - when(issueCache.byComponent("org.apache:struts")).thenReturn(Arrays.asList(newIssue(ruleKey))); - - List<Violation> violations = deprecatedViolations.get("org.apache:struts"); - - assertThat(violations).hasSize(1); - } -} diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java index 2b87b8b6c4a..d487aeadd6b 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssueFiltersTest.java @@ -21,10 +21,7 @@ package org.sonar.batch.issue; import org.junit.Test; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.batch.IssueFilter; import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.rules.Violation; -import org.sonar.batch.ViolationFilters; import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.any; @@ -33,9 +30,6 @@ import static org.mockito.Mockito.when; public class IssueFiltersTest { - DeprecatedViolations deprecatedViolations = mock(DeprecatedViolations.class); - ViolationFilters deprecatedFilters = mock(ViolationFilters.class); - @Test public void accept_when_filter_chain_is_empty() throws Exception { org.sonar.api.issue.IssueFilter ok = mock(org.sonar.api.issue.IssueFilter.class); @@ -44,30 +38,19 @@ public class IssueFiltersTest { org.sonar.api.issue.IssueFilter ko = mock(org.sonar.api.issue.IssueFilter.class); when(ko.accept(any(Issue.class))).thenReturn(false); - when(deprecatedFilters.isEmpty()).thenReturn(true); - IssueFilters filters = new IssueFilters(deprecatedFilters, deprecatedViolations, new org.sonar.api.issue.IssueFilter[]{ok, ko}); - assertThat(filters.accept(new DefaultIssue(), null)).isFalse(); + IssueFilters filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ok, ko}); + assertThat(filters.accept(new DefaultIssue())).isFalse(); - filters = new IssueFilters(deprecatedFilters, deprecatedViolations, new org.sonar.api.issue.IssueFilter[]{ok}); - assertThat(filters.accept(new DefaultIssue(), null)).isTrue(); + filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ok}); + assertThat(filters.accept(new DefaultIssue())).isTrue(); - filters = new IssueFilters(deprecatedFilters, deprecatedViolations, new org.sonar.api.issue.IssueFilter[]{ko}); - assertThat(filters.accept(new DefaultIssue(), null)).isFalse(); + filters = new IssueFilters(new org.sonar.api.issue.IssueFilter[] {ko}); + assertThat(filters.accept(new DefaultIssue())).isFalse(); } @Test public void should_always_accept_if_no_filters() { - when(deprecatedFilters.isEmpty()).thenReturn(true); - IssueFilters filters = new IssueFilters(deprecatedFilters, deprecatedViolations); - assertThat(filters.accept(new DefaultIssue(), null)).isTrue(); - } - - @Test - public void should_check_deprecated_violation_filters() throws Exception { - when(deprecatedFilters.isEmpty()).thenReturn(false); - when(deprecatedFilters.isIgnored(any(Violation.class))).thenReturn(true); - IssueFilters filters = new IssueFilters(deprecatedFilters, deprecatedViolations, new org.sonar.api.issue.IssueFilter[0]); - assertThat(filters.accept(new DefaultIssue(), null)).isFalse(); - + IssueFilters filters = new IssueFilters(); + assertThat(filters.accept(new DefaultIssue())).isTrue(); } } 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 ef507f38001..1516c7a8ddb 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 @@ -46,7 +46,6 @@ import java.util.Date; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; @@ -147,7 +146,7 @@ public class ModuleIssuesTest { .setKey("ABCDE") .setRuleKey(SQUID_RULE_KEY) .setSeverity(Severity.CRITICAL); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); boolean added = moduleIssues.initAndAddIssue(issue); @@ -168,7 +167,7 @@ public class ModuleIssuesTest { when(project.getAnalysisDate()).thenReturn(analysisDate); DefaultIssue issue = new DefaultIssue().setRuleKey(SQUID_RULE_KEY).setSeverity(null); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); moduleIssues.initAndAddIssue(issue); ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); @@ -191,7 +190,7 @@ public class ModuleIssuesTest { .setRuleKey(SQUID_RULE_KEY) .setSeverity(Severity.CRITICAL) .setMessage(""); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); boolean added = moduleIssues.initAndAddIssue(issue); @@ -214,7 +213,7 @@ public class ModuleIssuesTest { violation.setSeverity(RulePriority.CRITICAL); violation.setMessage("the message"); - when(filters.accept(any(DefaultIssue.class), eq(violation))).thenReturn(true); + when(filters.accept(any(DefaultIssue.class))).thenReturn(true); boolean added = moduleIssues.initAndAddViolation(violation); assertThat(added).isTrue(); @@ -242,7 +241,7 @@ public class ModuleIssuesTest { .setRuleKey(SQUID_RULE_KEY) .setSeverity(Severity.CRITICAL); - when(filters.accept(issue, null)).thenReturn(false); + when(filters.accept(issue)).thenReturn(false); boolean added = moduleIssues.initAndAddIssue(issue); @@ -268,7 +267,7 @@ public class ModuleIssuesTest { .setSeverity(Severity.CRITICAL) .setEffortToFix(2d); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); moduleIssues.initAndAddIssue(issue); ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); @@ -294,7 +293,7 @@ public class ModuleIssuesTest { .setSeverity(Severity.CRITICAL) .setEffortToFix(2d); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); moduleIssues.initAndAddIssue(issue); ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); @@ -320,7 +319,7 @@ public class ModuleIssuesTest { .setSeverity(Severity.CRITICAL) .setEffortToFix(null); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); moduleIssues.initAndAddIssue(issue); ArgumentCaptor<DefaultIssue> argument = ArgumentCaptor.forClass(DefaultIssue.class); @@ -343,7 +342,7 @@ public class ModuleIssuesTest { .setSeverity(Severity.CRITICAL) .setEffortToFix(2d); - when(filters.accept(issue, null)).thenReturn(true); + when(filters.accept(issue)).thenReturn(true); try { moduleIssues.initAndAddIssue(issue); |