aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-02-10 14:59:36 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2015-02-10 15:34:18 +0100
commit9fb2ca6c4d1257c6387f108ffbca0cf09e802704 (patch)
treecdc3b112641993007f6d53767bf82bc280c3c7c3 /sonar-batch/src/test/java
parentdb911e46da06f2339afa889acb3c8f1e7bbe5ae9 (diff)
downloadsonarqube-9fb2ca6c4d1257c6387f108ffbca0cf09e802704.tar.gz
sonarqube-9fb2ca6c4d1257c6387f108ffbca0cf09e802704.zip
SONAR-6068 Improve performance of FileSystem query operation
Diffstat (limited to 'sonar-batch/src/test/java')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java49
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java136
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java17
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java17
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java16
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java3
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java44
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java9
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java8
13 files changed, 266 insertions, 63 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
index b71425b3ffb..0caa8cf219e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/debt/SqaleRatingDecoratorTest.java
@@ -73,7 +73,7 @@ public class SqaleRatingDecoratorTest {
public void setUp() throws Exception {
settings = new Settings();
- fs = new DefaultFileSystem();
+ fs = new DefaultFileSystem(temp.newFolder());
fs.add(new DefaultInputFile("foo", file.getPath())
.setLanguage("java")
.setFile(temp.newFile("Foo.java")));
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
index 30002ec7f4c..9fd36ece0b7 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
@@ -65,13 +65,14 @@ public class IssueExclusionsLoaderTest {
@Mock
private PatternMatcher patternMatcher;
- DefaultFileSystem fs = new DefaultFileSystem().setEncoding(UTF_8);
- IssueExclusionsLoader scanner;
- File baseDir;
+ private DefaultFileSystem fs;
+ private IssueExclusionsLoader scanner;
+ private File baseDir;
@Before
- public void before() throws IOException {
+ public void before() throws Exception {
baseDir = temp.newFolder();
+ fs = new DefaultFileSystem(baseDir).setEncoding(UTF_8);
MockitoAnnotations.initMocks(this);
scanner = new IssueExclusionsLoader(regexpScanner, exclusionPatternInitializer, inclusionPatternInitializer, fs);
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java
new file mode 100644
index 00000000000..49d0ff34f35
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java
@@ -0,0 +1,49 @@
+/*
+ * 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.mediumtest;
+
+import org.hamcrest.Matchers;
+import org.junit.rules.ErrorCollector;
+import org.slf4j.LoggerFactory;
+
+public class Benchmark extends ErrorCollector {
+
+ private static final boolean ENABLED = "true".equals(System.getProperty("enableBenchmarkAssertions"));
+
+ static {
+ if (ENABLED) {
+ LoggerFactory.getLogger(Benchmark.class).warn("Assertions are calibrated for SonarSource dedicated box. " +
+ "They can be disabled by setting the property -DenableBenchmarkAssertions=false.");
+ }
+ }
+
+ public void expectBetween(String label, long val, long min, long max) {
+ if (ENABLED) {
+ checkThat(label, val, Matchers.allOf(Matchers.greaterThan(min), Matchers.lessThan(max)));
+ }
+ }
+
+ public void expectLessThanOrEqualTo(String label, long val, long max) {
+ if (ENABLED) {
+ checkThat(label, val, Matchers.lessThan(max));
+ }
+ }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java
new file mode 100644
index 00000000000..7579314569a
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java
@@ -0,0 +1,136 @@
+/*
+ * 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.mediumtest.fs;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableMap;
+import org.apache.commons.io.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.batch.mediumtest.BatchMediumTester;
+import org.sonar.batch.mediumtest.Benchmark;
+import org.sonar.batch.mediumtest.TaskResult;
+import org.sonar.batch.protocol.input.ActiveRule;
+import org.sonar.xoo.XooPlugin;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class RandomFsAccessMediumTest {
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
+ public Benchmark bench = new Benchmark();
+
+ public BatchMediumTester tester = BatchMediumTester.builder()
+ .registerPlugin("xoo", new XooPlugin())
+ .addDefaultQProfile("xoo", "Sonar Way")
+ .activateRule(new ActiveRule("xoo", "RandomAccessIssue", null, "One issue per line", "MAJOR", null, "xoo"))
+ .build();
+
+ @Before
+ public void prepare() {
+ tester.start();
+ }
+
+ @After
+ public void stop() {
+ tester.stop();
+ }
+
+ @Test
+ public void testRandomFsAccessByAbsolutePath() throws IOException {
+
+ File baseDir = temp.newFolder();
+ File srcDir = prepareBigProject(baseDir);
+
+ File paths = new File(baseDir, "paths.txt");
+ int ISSUE_COUNT = 10000;
+ for (int i = 0; i < ISSUE_COUNT; i++) {
+ File xooFile = new File(srcDir, "sample" + (i / 10 + 1) + ".xoo");
+ FileUtils.write(paths, xooFile.getAbsolutePath() + "\n", Charsets.UTF_8, true);
+ }
+
+ long start = System.currentTimeMillis();
+ TaskResult result = tester.newTask()
+ .properties(ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectName", "Foo Project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project")
+ .put("sonar.sources", "src")
+ .put("sonar.xoo.randomAccessIssue.paths", paths.getAbsolutePath())
+ .build())
+ .start();
+
+ assertThat(result.issues()).hasSize(ISSUE_COUNT);
+ bench.expectLessThanOrEqualTo("Time to create " + ISSUE_COUNT + " issues on random files using FileSystem query", System.currentTimeMillis() - start, 2000);
+ }
+
+ @Test
+ public void testRandomFsAccessByRelativePath() throws IOException {
+
+ File baseDir = temp.newFolder();
+ File srcDir = prepareBigProject(baseDir);
+
+ File paths = new File(baseDir, "paths.txt");
+ int ISSUE_COUNT = 10000;
+ for (int i = 0; i < ISSUE_COUNT; i++) {
+ FileUtils.write(paths, "src/sample" + (i / 10 + 1) + ".xoo\n", Charsets.UTF_8, true);
+ }
+
+ TaskResult result = tester.newTask()
+ .properties(ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectName", "Foo Project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project")
+ .put("sonar.sources", "src")
+ .put("sonar.xoo.randomAccessIssue.paths", paths.getAbsolutePath())
+ .build())
+ .start();
+
+ assertThat(result.issues()).hasSize(ISSUE_COUNT);
+
+ }
+
+ private File prepareBigProject(File baseDir) throws IOException {
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ for (int i = 1; i <= 1000; i++) {
+ File xooFile = new File(srcDir, "sample" + i + ".xoo");
+ FileUtils.write(xooFile, "foo");
+ }
+ return srcDir;
+ }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
index 2da2400c0cd..c9e6deabcaf 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileSensorTest.java
@@ -19,7 +19,10 @@
*/
package org.sonar.batch.rule;
+import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.measures.CoreMetrics;
@@ -32,10 +35,15 @@ import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.argThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class QProfileSensorTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
static final Date DATE = UtcDateUtils.parseDateTime("2014-01-15T12:00:00+0000");
static final QProfile JAVA_PROFILE = new QProfile().setKey("java-two").setName("Java Two").setLanguage("java")
.setRulesUpdatedAt(DATE);
@@ -45,7 +53,12 @@ public class QProfileSensorTest {
ModuleQProfiles moduleQProfiles = mock(ModuleQProfiles.class);
Project project = mock(Project.class);
SensorContext sensorContext = mock(SensorContext.class);
- DefaultFileSystem fs = new DefaultFileSystem();
+ DefaultFileSystem fs;
+
+ @Before
+ public void prepare() throws Exception {
+ fs = new DefaultFileSystem(temp.newFolder());
+ }
@Test
public void to_string() throws Exception {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
index da457212cd5..9c5db0f6d6a 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileVerifierTest.java
@@ -23,24 +23,31 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class QProfileVerifierTest {
@Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
public ExpectedException thrown = ExpectedException.none();
- DefaultFileSystem fs = new DefaultFileSystem();
- ModuleQProfiles profiles;
- Settings settings = new Settings();
+ private DefaultFileSystem fs;
+ private ModuleQProfiles profiles;
+ private Settings settings = new Settings();
@Before
- public void before() {
+ public void before() throws Exception {
+ fs = new DefaultFileSystem(temp.newFolder());
profiles = mock(ModuleQProfiles.class);
QProfile javaProfile = new QProfile().setKey("p1").setName("My Java profile").setLanguage("java");
when(profiles.findByLanguage("java")).thenReturn(javaProfile);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
index 1c9531cefc1..a60fd596e53 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/LanguageVerifierTest.java
@@ -19,9 +19,11 @@
*/
package org.sonar.batch.scan;
+import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Java;
@@ -34,13 +36,21 @@ import static org.assertj.core.api.Assertions.assertThat;
public class LanguageVerifierTest {
- Settings settings = new Settings();
- LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE));
- DefaultFileSystem fs = new DefaultFileSystem();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
@Rule
public ExpectedException thrown = ExpectedException.none();
+ private Settings settings = new Settings();
+ private LanguagesReferential languages = new DefaultLanguagesReferential(new Languages(Java.INSTANCE));
+ private DefaultFileSystem fs;
+
+ @Before
+ public void prepare() throws Exception {
+ fs = new DefaultFileSystem(temp.newFolder());
+ }
+
@Test
public void language_is_not_set() throws Exception {
LanguageVerifier verifier = new LanguageVerifier(settings, languages, fs);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
index a3d770937f7..702aa2fb068 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/ComponentIndexerTest.java
@@ -48,7 +48,7 @@ public class ComponentIndexerTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
private File baseDir;
- private DefaultFileSystem fs = new DefaultFileSystem();
+ private DefaultFileSystem fs;
private SonarIndex sonarIndex;
private AbstractLanguage cobolLanguage;
private Project project;
@@ -56,6 +56,7 @@ public class ComponentIndexerTest {
@Before
public void prepare() throws IOException {
baseDir = temp.newFolder();
+ fs = new DefaultFileSystem(baseDir);
sonarIndex = mock(SonarIndex.class);
project = new Project("myProject");
cobolLanguage = new AbstractLanguage("cobol") {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
index 5e55be940d5..12be0438530 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystemTest.java
@@ -58,13 +58,13 @@ public class DefaultModuleFileSystemTest {
@Test
public void test_equals_and_hashCode() throws Exception {
- DefaultModuleFileSystem foo1 = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem foo1 = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
- DefaultModuleFileSystem foo2 = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem foo2 = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
- DefaultModuleFileSystem bar = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem bar = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("bar"), settings, fileIndexer, initializer, componentIndexer);
- DefaultModuleFileSystem branch = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem branch = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("bar", "branch", "My project"), settings, fileIndexer, initializer, componentIndexer);
assertThat(foo1.moduleKey()).isEqualTo("foo");
@@ -79,7 +79,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void default_source_encoding() {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
assertThat(fs.sourceCharset()).isEqualTo(Charset.defaultCharset());
@@ -89,7 +89,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void source_encoding_is_set() {
settings.setProperty(CoreProperties.ENCODING_PROPERTY, "Cp1124");
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
assertThat(fs.encoding()).isEqualTo(Charset.forName("Cp1124"));
@@ -119,7 +119,7 @@ public class DefaultModuleFileSystemTest {
javaTest.mkdirs();
when(initializer.tests()).thenReturn(Arrays.asList(javaTest, additionalTest));
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(basedir.getCanonicalPath());
@@ -131,34 +131,8 @@ public class DefaultModuleFileSystemTest {
}
@Test
- public void should_reset_dirs() throws IOException {
- File basedir = temp.newFolder();
- when(initializer.baseDir()).thenReturn(basedir);
- when(initializer.workingDir()).thenReturn(basedir);
- when(initializer.sources()).thenReturn(Arrays.asList(new File(basedir, "src/main/java")));
-
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
- new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
-
- File existingDir = temp.newFolder("new_folder");
- File notExistingDir = new File(existingDir, "not_exist");
-
- fs.resetDirs(existingDir, existingDir,
- Lists.newArrayList(existingDir, notExistingDir), Lists.newArrayList(existingDir, notExistingDir), Lists.newArrayList(existingDir, notExistingDir));
-
- assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(existingDir.getCanonicalPath());
- assertThat(fs.buildDir().getCanonicalPath()).isEqualTo(existingDir.getCanonicalPath());
- assertThat(fs.sourceDirs()).hasSize(1);
- assertThat(fs.sourceDirs().get(0).getCanonicalPath()).isEqualTo(existingDir.getCanonicalPath());
- assertThat(fs.testDirs()).hasSize(1);
- assertThat(fs.testDirs().get(0).getCanonicalPath()).isEqualTo(existingDir.getCanonicalPath());
- assertThat(fs.binaryDirs()).hasSize(1);
- assertThat(fs.binaryDirs().get(0).getCanonicalPath()).isEqualTo(existingDir.getCanonicalPath());
- }
-
- @Test
public void should_search_input_files() throws Exception {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
File mainFile = temp.newFile();
@@ -176,7 +150,7 @@ public class DefaultModuleFileSystemTest {
@Test
public void should_index() throws Exception {
- DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
+ DefaultModuleFileSystem fs = new DefaultModuleFileSystem(moduleInputFileCache,
new Project("foo"), settings, fileIndexer, initializer, componentIndexer);
verifyZeroInteractions(fileIndexer);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
index 4eee91caad3..786d5a7f040 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
@@ -64,11 +64,11 @@ public class JSONReportTest {
private SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
@org.junit.Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ public TemporaryFolder temp = new TemporaryFolder();
JSONReport jsonReport;
Resource resource = mock(Resource.class);
- DefaultFileSystem fs = new DefaultFileSystem();
+ DefaultFileSystem fs;
Server server = mock(Server.class);
ActiveRules activeRules = mock(ActiveRules.class);
Settings settings = new Settings();
@@ -76,7 +76,8 @@ public class JSONReportTest {
private UserRepository userRepository;
@Before
- public void before() {
+ public void before() throws Exception {
+ fs = new DefaultFileSystem(temp.newFolder());
SIMPLE_DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+02:00"));
when(resource.getEffectiveKey()).thenReturn("Action.java");
when(server.getVersion()).thenReturn("3.6");
@@ -161,7 +162,7 @@ public class JSONReportTest {
@Test
public void should_export_issues_to_file() throws IOException {
- File workDir = temporaryFolder.newFolder("sonar");
+ File workDir = temp.newFolder("sonar");
fs.setWorkDir(workDir);
when(jsonReport.getIssues()).thenReturn(Collections.<DefaultIssue>emptyList());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
index 882bc1aadc7..d0cf02f65a3 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/AnalyzerOptimizerTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
@@ -39,18 +40,20 @@ import static org.mockito.Mockito.when;
public class AnalyzerOptimizerTest {
- DefaultFileSystem fs = new DefaultFileSystem();
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
@Rule
public ExpectedException thrown = ExpectedException.none();
- private AnalyzerOptimizer optimizer;
+ private DefaultFileSystem fs;
+ private AnalyzerOptimizer optimizer;
private Settings settings;
-
private AnalysisMode analysisMode;
@Before
- public void prepare() {
+ public void prepare() throws Exception {
+ fs = new DefaultFileSystem(temp.newFolder());
settings = new Settings();
analysisMode = mock(AnalysisMode.class);
optimizer = new AnalyzerOptimizer(fs, new ActiveRulesBuilder().build(), settings, analysisMode);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
index 0995806e053..e6d24b0643f 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorContextTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.AnalysisMode;
import org.sonar.api.batch.fs.internal.DefaultFileSystem;
import org.sonar.api.batch.measure.MetricFinder;
@@ -42,6 +43,9 @@ import static org.mockito.Mockito.when;
public class DefaultSensorContextTest {
@Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
public ExpectedException thrown = ExpectedException.none();
private ActiveRules activeRules;
@@ -52,9 +56,9 @@ public class DefaultSensorContextTest {
private AnalysisMode analysisMode;
@Before
- public void prepare() {
+ public void prepare() throws Exception {
activeRules = new ActiveRulesBuilder().build();
- fs = new DefaultFileSystem();
+ fs = new DefaultFileSystem(temp.newFolder());
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
index c977124e861..658f48e41fd 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java
@@ -23,6 +23,7 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.batch.fs.InputFile;
@@ -67,6 +68,9 @@ import static org.mockito.Mockito.when;
public class DefaultSensorStorageTest {
@Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ @Rule
public ExpectedException thrown = ExpectedException.none();
private ActiveRules activeRules;
@@ -78,9 +82,9 @@ public class DefaultSensorStorageTest {
private DefaultIndex sonarIndex;
@Before
- public void prepare() {
+ public void prepare() throws Exception {
activeRules = new ActiveRulesBuilder().build();
- fs = new DefaultFileSystem();
+ fs = new DefaultFileSystem(temp.newFolder());
MetricFinder metricFinder = mock(MetricFinder.class);
when(metricFinder.findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
when(metricFinder.findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);