aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-11 15:54:24 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-08-12 16:12:50 +0200
commitdd2c4c54c3d18939cdf92d86ce6a1576768bd567 (patch)
tree40298bc02e36866bb04cad3db5eebae900185eed /sonar-batch/src
parent3be4a0c53385a59c40e87f7e8ba5283b1c5928d3 (diff)
downloadsonarqube-dd2c4c54c3d18939cdf92d86ce6a1576768bd567.tar.gz
sonarqube-dd2c4c54c3d18939cdf92d86ce6a1576768bd567.zip
Improve tests
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java85
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java61
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java33
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheStatusTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java42
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java44
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java4
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java20
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java2
27 files changed, 206 insertions, 147 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
new file mode 100644
index 00000000000..191b5872e48
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
@@ -0,0 +1,85 @@
+/*
+ * 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.cache;
+
+import org.sonar.batch.bootstrap.ServerClient;
+import org.sonar.home.cache.PersistentCache;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+
+public class DefaultProjectCacheStatus implements ProjectCacheStatus {
+ private static final String STATUS_PREFIX = "cache-sync-status-";
+ private PersistentCache cache;
+ private ServerClient client;
+
+ public DefaultProjectCacheStatus(PersistentCache cache, ServerClient client) {
+ this.cache = cache;
+ this.client = client;
+ }
+
+ @Override
+ public void save(String projectKey) {
+ Date now = new Date();
+
+ try {
+ ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
+ try (ObjectOutputStream objOutput = new ObjectOutputStream(byteOutput)) {
+ objOutput.writeObject(now);
+ }
+ cache.put(getKey(projectKey), byteOutput.toByteArray());
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to write cache sync status", e);
+ }
+ }
+
+ @Override
+ public void delete(String projectKey) {
+ try {
+ cache.put(getKey(projectKey), new byte[0]);
+ } catch (IOException e) {
+ throw new IllegalStateException("Failed to delete cache sync status", e);
+ }
+ }
+
+ @Override
+ public Date getSyncStatus(String projectKey) {
+ try {
+ byte[] status = cache.get(getKey(projectKey), null);
+ if (status == null || status.length == 0) {
+ return null;
+ }
+ ByteArrayInputStream byteInput = new ByteArrayInputStream(status);
+ try (ObjectInputStream objInput = new ObjectInputStream(byteInput)) {
+ return (Date) objInput.readObject();
+ }
+ } catch (IOException | ClassNotFoundException e) {
+ throw new IllegalStateException("Failed to read cache sync status", e);
+ }
+ }
+
+ private String getKey(String projectKey) {
+ return STATUS_PREFIX + client.getURL() + projectKey;
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
index d36e0b427ad..281cd60f344 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectCacheStatus.java
@@ -19,65 +19,12 @@
*/
package org.sonar.batch.cache;
-import org.sonar.batch.bootstrap.ServerClient;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
import java.util.Date;
-import org.sonar.home.cache.PersistentCache;
-
-public class ProjectCacheStatus {
- private static final String STATUS_PREFIX = "cache-sync-status-";
- private PersistentCache cache;
- private ServerClient client;
-
- public ProjectCacheStatus(PersistentCache cache, ServerClient client) {
- this.cache = cache;
- this.client = client;
- }
-
- public void save(String projectKey) {
- Date now = new Date();
-
- try {
- ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
- try (ObjectOutputStream objOutput = new ObjectOutputStream(byteOutput)) {
- objOutput.writeObject(now);
- }
- cache.put(getKey(projectKey), byteOutput.toByteArray());
- } catch (IOException e) {
- throw new IllegalStateException("Failed to write cache sync status", e);
- }
- }
-
- public void delete(String projectKey) {
- try {
- cache.put(getKey(projectKey), new byte[0]);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to delete cache sync status", e);
- }
- }
+public interface ProjectCacheStatus {
+ void save(String projectKey);
- public Date getSyncStatus(String projectKey) {
- try {
- byte[] status = cache.get(getKey(projectKey), null);
- if (status == null || status.length == 0) {
- return null;
- }
- ByteArrayInputStream byteInput = new ByteArrayInputStream(status);
- try (ObjectInputStream objInput = new ObjectInputStream(byteInput)) {
- return (Date) objInput.readObject();
- }
- } catch (IOException | ClassNotFoundException e) {
- throw new IllegalStateException("Failed to read cache sync status", e);
- }
- }
+ void delete(String projectKey);
- private String getKey(String projectKey) {
- return STATUS_PREFIX + client.getURL() + projectKey;
- }
+ Date getSyncStatus(String projectKey);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
index 4be7ab575f4..ad599572315 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/cache/ProjectSyncContainer.java
@@ -72,10 +72,10 @@ public class ProjectSyncContainer extends ComponentContainer {
add(new StrategyWSLoaderProvider(LoadStrategy.SERVER_FIRST),
properties,
ProjectAnalysisMode.class,
- ProjectCacheStatus.class,
ProjectCacheSynchronizer.class,
UserRepositoryLoader.class);
+ addIfMissing(DefaultProjectCacheStatus.class, ProjectCacheStatus.class);
addIfMissing(DefaultProjectRepositoriesLoader.class, ProjectRepositoriesLoader.class);
addIfMissing(DefaultServerIssuesLoader.class, ServerIssuesLoader.class);
addIfMissing(DefaultServerLineHashesLoader.class, ServerLineHashesLoader.class);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
index d701489cca4..0ac0c6e4398 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/GlobalContainerTest.java
@@ -19,21 +19,39 @@
*/
package org.sonar.batch.bootstrap;
+import org.sonar.api.batch.BatchSide;
+
+import org.junit.Rule;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.CoreProperties;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.junit.Test;
-import org.sonar.api.BatchExtension;
import org.sonar.api.utils.TempFolder;
import org.sonar.core.config.Logback;
import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
public class GlobalContainerTest {
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+
+ private GlobalContainer createContainer(List<Object> extensions) {
+ Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
+ CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
+
+ GlobalContainer container = GlobalContainer.create(props, extensions, false);
+ container.doBeforeStart();
+ return container;
+ }
+
@Test
public void should_add_components() {
- GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Collections.emptyList(), false);
- container.doBeforeStart();
+ GlobalContainer container = createContainer(Collections.emptyList());
assertThat(container.getComponentByType(Logback.class)).isNotNull();
assertThat(container.getComponentByType(TempFolder.class)).isNotNull();
@@ -41,18 +59,19 @@ public class GlobalContainerTest {
@Test
public void should_add_bootstrap_extensions() {
- GlobalContainer container = GlobalContainer.create(Collections.<String, String>emptyMap(), Lists.newArrayList(Foo.class, new Bar()), false);
- container.doBeforeStart();
+ GlobalContainer container = createContainer(Lists.newArrayList(Foo.class, new Bar()));
assertThat(container.getComponentByType(Foo.class)).isNotNull();
assertThat(container.getComponentByType(Bar.class)).isNotNull();
}
- public static class Foo implements BatchExtension {
+ @BatchSide
+ public static class Foo {
}
- public static class Bar implements BatchExtension {
+ @BatchSide
+ public static class Bar {
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheStatusTest.java b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheStatusTest.java
index 2b6c4491f62..34075f293f1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheStatusTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/cache/ProjectCacheStatusTest.java
@@ -47,7 +47,7 @@ public class ProjectCacheStatusTest {
cache = new PersistentCache(tmp.getRoot().toPath(), Long.MAX_VALUE, mock(Logger.class), null);
client = mock(ServerClient.class);
when(client.getURL()).thenReturn("localhost");
- cacheStatus = new ProjectCacheStatus(cache, client);
+ cacheStatus = new DefaultProjectCacheStatus(cache, client);
}
@Test
@@ -55,7 +55,7 @@ public class ProjectCacheStatusTest {
cacheStatus.save(PROJ_KEY);
assertThat(cacheStatus.getSyncStatus(PROJ_KEY)).isNotNull();
assertThat(age(cacheStatus.getSyncStatus(PROJ_KEY))).isLessThan(2000);
- assertThat(cacheStatus.getSyncStatus(PROJ_KEY+"1")).isNull();
+ assertThat(cacheStatus.getSyncStatus(PROJ_KEY + "1")).isNull();
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java
index 026f816cea4..b9f09a73254 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/AbstractCachesTest.java
@@ -20,7 +20,17 @@
package org.sonar.batch.index;
import org.junit.After;
+
import org.junit.Before;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import com.google.common.collect.ImmutableMap;
+import org.sonar.api.CoreProperties;
+import org.sonar.batch.bootstrap.BootstrapProperties;
+import org.sonar.batch.bootstrap.TempFolderProvider;
+
+import java.util.Map;
+
import org.junit.ClassRule;
import org.junit.rules.TemporaryFolder;
@@ -28,21 +38,24 @@ public abstract class AbstractCachesTest {
@ClassRule
public static TemporaryFolder temp = new TemporaryFolder();
- protected static final ThreadLocal<CachesManager> cachesManagers = new ThreadLocal<CachesManager>() {
- @Override
- protected CachesManager initialValue() {
- CachesManager cachesManager = CachesManagerTest.createCacheOnTemp(temp);
- cachesManager.start();
- return cachesManager;
- }
- };
-
- protected CachesManager cachesManager;
+ protected static CachesManager cachesManager;
protected Caches caches;
+ private static CachesManager createCacheOnTemp() {
+ Map<String, String> props = ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.getRoot().getAbsolutePath(),
+ CoreProperties.GLOBAL_WORKING_DIRECTORY, temp.getRoot().getAbsolutePath());
+
+ return new CachesManager(new TempFolderProvider().provide(new BootstrapProperties(props)));
+ }
+
+ @BeforeClass
+ public static void startClass() {
+ cachesManager = createCacheOnTemp();
+ cachesManager.start();
+ }
+
@Before
public void start() {
- cachesManager = cachesManagers.get();
caches = new Caches(cachesManager);
caches.start();
}
@@ -54,4 +67,11 @@ public abstract class AbstractCachesTest {
caches = null;
}
}
+
+ @AfterClass
+ public static void stopClass() {
+ if (cachesManager != null) {
+ cachesManager.stop();
+ }
+ }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java
index 6d301a7ec4d..e0e80a07883 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/CachesManagerTest.java
@@ -19,54 +19,24 @@
*/
package org.sonar.batch.index;
-import org.sonar.batch.bootstrap.TempFolderProvider;
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.ClassRule;
import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.CoreProperties;
-import org.sonar.batch.bootstrap.BootstrapProperties;
import java.io.File;
-import java.io.IOException;
import static org.assertj.core.api.Assertions.assertThat;
-public class CachesManagerTest {
-
- @ClassRule
- public static TemporaryFolder temp = new TemporaryFolder();
-
- public static CachesManager createCacheOnTemp(TemporaryFolder temp) {
- try {
- BootstrapProperties bootstrapProps = new BootstrapProperties(ImmutableMap.of(CoreProperties.WORKING_DIRECTORY, temp.newFolder().getAbsolutePath()));
- return new CachesManager(new TempFolderProvider().provide(bootstrapProps));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- CachesManager cachesMgr;
-
- @Before
- public void prepare() {
- cachesMgr = createCacheOnTemp(temp);
- cachesMgr.start();
- }
-
+public class CachesManagerTest extends AbstractCachesTest {
@Test
public void should_stop_and_clean_temp_dir() {
- File tempDir = cachesMgr.tempDir();
+ File tempDir = cachesManager.tempDir();
assertThat(tempDir).isDirectory().exists();
- assertThat(cachesMgr.persistit()).isNotNull();
- assertThat(cachesMgr.persistit().isInitialized()).isTrue();
+ assertThat(cachesManager.persistit()).isNotNull();
+ assertThat(cachesManager.persistit().isInitialized()).isTrue();
- cachesMgr.stop();
+ cachesManager.stop();
assertThat(tempDir).doesNotExist();
- assertThat(cachesMgr.tempDir()).isNull();
- assertThat(cachesMgr.persistit()).isNull();
+ assertThat(cachesManager.tempDir()).isNull();
+ assertThat(cachesManager.persistit()).isNull();
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
index 3e4ddedacf5..b4a80af70db 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/BatchMediumTester.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.mediumtest;
+import org.sonar.batch.cache.ProjectCacheStatus;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonarqube.ws.Rules.ListResponse.Rule;
import org.sonar.batch.bootstrapper.IssueListener;
@@ -86,6 +87,7 @@ public class BatchMediumTester {
private final FakeServerLineHashesLoader serverLineHashes = new FakeServerLineHashesLoader();
private final Map<String, String> bootstrapProperties = new HashMap<>();
private final FakeRulesLoader rulesLoader = new FakeRulesLoader();
+ private final FakeProjectCacheStatus projectCacheStatus = new FakeProjectCacheStatus();
private LogOutput logOutput = null;
public BatchMediumTester build() {
@@ -220,6 +222,7 @@ public class BatchMediumTester {
builder.serverIssues,
builder.serverLineHashes,
builder.rulesLoader,
+ builder.projectCacheStatus,
new DefaultDebtModel())
.setBootstrapProperties(builder.bootstrapProperties)
.setLogOutput(builder.logOutput)
@@ -393,6 +396,23 @@ public class BatchMediumTester {
}
+ private static class FakeProjectCacheStatus implements ProjectCacheStatus {
+
+ @Override
+ public void save(String projectKey) {
+ }
+
+ @Override
+ public void delete(String projectKey) {
+ }
+
+ @Override
+ public Date getSyncStatus(String projectKey) {
+ return new Date();
+ }
+
+ }
+
private static class FakeServerLineHashesLoader implements ServerLineHashesLoader {
private Map<String, String[]> byKey = new HashMap<>();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
index 581c32789dc..a0d2ef8b7f8 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cache/CacheSyncTest.java
@@ -70,7 +70,6 @@ public class CacheSyncTest {
tester.start();
tester.syncProject("test-project");
-
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java
index 79de3e1afa2..12483ea36d0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/coverage/CoverageMediumTest.java
@@ -61,7 +61,7 @@ public class CoverageMediumTest {
@Test
public void unitTests() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
@@ -101,7 +101,7 @@ public class CoverageMediumTest {
@Test
public void exclusions() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
index bc4aeb777cb..03b171ae31e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/cpd/CpdMediumTest.java
@@ -65,7 +65,7 @@ public class CpdMediumTest {
public void prepare() throws IOException {
tester.start();
- baseDir = temp.newFolder();
+ baseDir = temp.getRoot();
builder = ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java
index 660b861bece..a84b0bda342 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/deprecated/DeprecatedApiMediumTest.java
@@ -61,7 +61,7 @@ public class DeprecatedApiMediumTest {
@Test
public void testIssueDetails() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
index 9b0577ec5b8..321e89cb174 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/FileSystemMediumTest.java
@@ -61,7 +61,7 @@ public class FileSystemMediumTest {
public void prepare() throws IOException {
tester.start();
- baseDir = temp.newFolder();
+ baseDir = temp.getRoot();
builder = ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
index 42ef0b87433..917ac570c77 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/ProjectBuilderMediumTest.java
@@ -64,7 +64,7 @@ public class ProjectBuilderMediumTest {
@Test
public void testProjectBuilder() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File module1Dir = new File(baseDir, "module1");
module1Dir.mkdir();
@@ -104,7 +104,7 @@ public class ProjectBuilderMediumTest {
@Test
public void testProjectBuilderWithBranch() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File module1Dir = new File(baseDir, "module1");
module1Dir.mkdir();
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
index cfbd881e224..7fcc91ecaac 100644
--- 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
@@ -68,7 +68,7 @@ public class RandomFsAccessMediumTest {
@Test
public void testRandomFsAccessByAbsolutePath() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = prepareBigProject(baseDir);
File paths = new File(baseDir, "paths.txt");
@@ -100,8 +100,8 @@ public class RandomFsAccessMediumTest {
@Test
public void testRandomFsAccessByRelativePath() throws IOException {
- File baseDir = temp.newFolder();
- File srcDir = prepareBigProject(baseDir);
+ File baseDir = temp.getRoot();
+ prepareBigProject(baseDir);
File paths = new File(baseDir, "paths.txt");
int ISSUE_COUNT = 10000;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java
index 2750688ddc1..6b43beeb609 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/ChecksMediumTest.java
@@ -65,7 +65,7 @@ public class ChecksMediumTest {
@Test
public void testCheckWithTemplate() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java
index 59ef4b792c4..bb44b2390d3 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesIssuesModeMediumTest.java
@@ -66,7 +66,7 @@ public class IssuesIssuesModeMediumTest {
@Test
public void testIssueCallback() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
- File tmpDir = temp.newFolder();
+ File tmpDir = temp.getRoot();
FileUtils.copyDirectory(projectDir, tmpDir);
IssueRecorder issueListener = new IssueRecorder();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
index 928c17dd47e..97b7d3fe52e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesMediumTest.java
@@ -64,7 +64,7 @@ public class IssuesMediumTest {
@Test
public void testNoIssueCallbackInNonPreview() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
- File tmpDir = temp.newFolder();
+ File tmpDir = temp.getRoot();
FileUtils.copyDirectory(projectDir, tmpDir);
IssueRecorder issueListener = new IssueRecorder();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java
index d181918a16b..a5cb1e212aa 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/IssuesOnDirMediumTest.java
@@ -60,7 +60,7 @@ public class IssuesOnDirMediumTest {
@Test
public void scanTempProject() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
index b5a6cdc14dd..48db6fb0aae 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issues/MultilineIssuesMediumTest.java
@@ -56,7 +56,7 @@ public class MultilineIssuesMediumTest {
tester.start();
File projectDir = new File(MultilineIssuesMediumTest.class.getResource("/mediumtest/xoo/sample-multiline").toURI());
- File tmpDir = temp.newFolder();
+ File tmpDir = temp.getRoot();
FileUtils.copyDirectory(projectDir, tmpDir);
result = tester
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
index 02e9a6a718d..ec5c630ab8b 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/issuesmode/IssueModeAndReportsMediumTest.java
@@ -43,7 +43,6 @@ import org.sonar.api.utils.log.LogTester;
import org.sonar.batch.bootstrapper.IssueListener;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.batch.mediumtest.TaskResult;
-import org.sonar.batch.mediumtest.issues.IssuesMediumTest;
import org.sonar.batch.protocol.Constants.Severity;
import org.sonar.batch.protocol.input.ActiveRule;
import org.sonar.batch.scan.report.ConsoleReport;
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
index 98d18d5a461..186c15c8931 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/log/LogListenerTest.java
@@ -90,7 +90,7 @@ public class LogListenerTest {
logOutput = new LinkedList<>();
tester.start();
- baseDir = temp.newFolder();
+ baseDir = temp.getRoot();
builder = ImmutableMap.<String, String>builder()
.put("sonar.task", "scan")
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
index f25b28fedc9..9212cc46512 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/measures/MeasuresMediumTest.java
@@ -44,6 +44,9 @@ public class MeasuresMediumTest {
@org.junit.Rule
public TemporaryFolder temp = new TemporaryFolder();
+ private File baseDir;
+ private File srcDir;
+
public BatchMediumTester tester = BatchMediumTester.builder()
.registerPlugin("xoo", new XooPlugin())
.addDefaultQProfile("xoo", "Sonar Way")
@@ -59,13 +62,15 @@ public class MeasuresMediumTest {
tester.stop();
}
- @Test
- public void computeMeasuresOnTempProject() throws IOException {
-
- File baseDir = temp.newFolder();
- File srcDir = new File(baseDir, "src");
+ @Before
+ public void setUp() {
+ baseDir = temp.getRoot();
+ srcDir = new File(baseDir, "src");
srcDir.mkdir();
+ }
+ @Test
+ public void computeMeasuresOnTempProject() throws IOException {
File xooFile = new File(srcDir, "sample.xoo");
File xooMeasureFile = new File(srcDir, "sample.xoo.measures");
FileUtils.write(xooFile, "Sample xoo\ncontent");
@@ -96,11 +101,6 @@ public class MeasuresMediumTest {
@Test
public void computeLinesOnAllFiles() throws IOException {
-
- File baseDir = temp.newFolder();
- File srcDir = new File(baseDir, "src");
- srcDir.mkdir();
-
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\n\ncontent");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java
index 24484442e70..2dfe12c6b34 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/scm/ScmMediumTest.java
@@ -251,7 +251,7 @@ public class ScmMediumTest {
}
private File prepareProject() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java
index 5f094972269..15bb71b6c75 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/symbol/SymbolMediumTest.java
@@ -58,7 +58,7 @@ public class SymbolMediumTest {
@Test
public void computeSymbolReferencesOnTempProject() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java
index be0ba5e9207..19ecaeb8df2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/CoveragePerTestMediumTest.java
@@ -58,7 +58,7 @@ public class CoveragePerTestMediumTest {
@Test
public void coveragePerTestInReport() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File testDir = new File(baseDir, "test");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java
index 2e96cd42156..0c26496e5ee 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/tests/TestExecutionMediumTest.java
@@ -59,7 +59,7 @@ public class TestExecutionMediumTest {
@Test
public void unitTests() throws IOException {
- File baseDir = temp.newFolder();
+ File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File testDir = new File(baseDir, "test");