aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java/org
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-02-10 16:54:15 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-02-10 17:07:03 +0100
commit7f0b376d36e1211e5876011f31af2764f1483d56 (patch)
treea60f6ffe1f1cd4ba85db6489d3979e6b26de4bde /sonar-batch/src/test/java/org
parent5eaa8f5ba79468354e84bb3fd9c8b8a581e65faa (diff)
downloadsonarqube-7f0b376d36e1211e5876011f31af2764f1483d56.tar.gz
sonarqube-7f0b376d36e1211e5876011f31af2764f1483d56.zip
SONAR-926 deprecate org.sonar.api.batch.ResourceFilter
Diffstat (limited to 'sonar-batch/src/test/java/org')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java47
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java48
2 files changed, 57 insertions, 38 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java b/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java
new file mode 100644
index 00000000000..8c4c58e413b
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/ResourceFiltersTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.sonar.api.batch.ResourceFilter;
+
+import static org.mockito.Matchers.startsWith;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class ResourceFiltersTest {
+ @Test
+ public void warn_on_resource_filters() throws Exception {
+ Logger logger = mock(Logger.class);
+ ResourceFilter[] filters = {mock(ResourceFilter.class)};
+ new ResourceFilters(logger, filters);
+ verify(logger).warn(startsWith("ResourceFilters are not supported since version 4.2"));
+
+ // verify that the standard constructor does not fail
+ new ResourceFilters(filters);
+ }
+
+ @Test
+ public void ok_if_no_resource_filters() throws Exception {
+ // just for verify that it does not fail. Should check that no warning is logged.
+ new ResourceFilters();
+ }
+}
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 68a085c6439..dd5da90948d 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
@@ -19,30 +19,21 @@
*/
package org.sonar.batch.index;
-import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
-import org.sonar.api.batch.ResourceFilter;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilters;
import org.sonar.api.measures.MetricFinder;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.*;
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.ResourceFilters;
import org.sonar.batch.issue.DeprecatedViolations;
import org.sonar.batch.issue.ModuleIssues;
import org.sonar.core.component.ScanGraph;
@@ -60,18 +51,14 @@ public class DefaultIndexTest {
@org.junit.Rule
public TemporaryFolder temp = new TemporaryFolder();
- private DefaultIndex index = null;
- private DeprecatedViolations deprecatedViolations;
- private Rule rule;
- private RuleFinder ruleFinder;
-
- private Project project;
-
- private Project moduleA;
-
- private Project moduleB;
-
- private Project moduleB1;
+ DefaultIndex index = null;
+ DeprecatedViolations deprecatedViolations;
+ Rule rule;
+ RuleFinder ruleFinder;
+ Project project;
+ Project moduleA;
+ Project moduleB;
+ Project moduleB1;
@Before
public void createIndex() throws IOException {
@@ -93,17 +80,11 @@ public class DefaultIndexTest {
moduleB1 = new Project("moduleB1").setParent(moduleB);
when(projectTree.getProjectDefinition(moduleB1)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1")));
- ResourceFilter filter = new ResourceFilter() {
-
- public boolean isIgnored(Resource resource) {
- return StringUtils.containsIgnoreCase(resource.getKey(), "excluded");
- }
- };
RulesProfile rulesProfile = RulesProfile.create();
rule = Rule.create("repoKey", "ruleKey", "Rule");
rule.setId(1);
rulesProfile.activateRule(rule, null);
- index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] {filter}), mock(ModuleIssues.class));
+ index.setCurrentProject(project, mock(ModuleIssues.class));
index.doStart(project);
}
@@ -165,15 +146,6 @@ public class DefaultIndexTest {
}
@Test
- public void shouldBeExcluded() {
- File file = File.create("src/org/foo/ExcludedBar.java", "org/foo/ExcludedBar.java", null, false);
- assertThat(index.index(file)).isFalse();
- assertThat(index.isIndexed(file, true)).isTrue();
- assertThat(index.isIndexed(file, false)).isFalse();
- assertThat(index.isExcluded(file)).isTrue();
- }
-
- @Test
public void shouldIndexResourceWhenAddingMeasure() {
Resource dir = Directory.create("src/org/foo", "org/foo");
index.addMeasure(dir, new Measure("ncloc").setValue(50.0));