aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java21
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java1
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java5
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java33
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java175
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java11
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java22
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java10
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java12
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java13
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java15
14 files changed, 170 insertions, 166 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
index 70d601aa396..c99fd70d838 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
@@ -29,30 +29,29 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.resources.Project;
import org.sonar.batch.bootstrap.ProjectFilter;
-import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class ProjectTree {
- private ProjectConfigurator configurator;
+ private final ProjectConfigurator configurator;
private ProjectReactor projectReactor;
private List<Project> projects;
private Map<ProjectDefinition, Project> projectsByDef;
private ProjectFilter projectFilter;
- public ProjectTree(ProjectReactor projectReactor, //NOSONAR the unused parameter 'builders' is used for the startup order of components
- ProjectConfigurator projectConfigurator,
- ProjectFilter projectFilter,
- /* Must be executed after ProjectBuilders */ ProjectBuilder[] builders) {
+ public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
+ ProjectConfigurator projectConfigurator,
+ ProjectFilter projectFilter,
+ /* Must be executed after ProjectBuilders */ProjectBuilder[] builders) {
this(projectReactor, projectConfigurator, projectFilter);
}
- public ProjectTree(ProjectReactor projectReactor, //NOSONAR the unused parameter 'builders' is used for the startup order of components
- ProjectConfigurator projectConfigurator,
- ProjectFilter projectFilter) {
+ public ProjectTree(ProjectReactor projectReactor, // NOSONAR the unused parameter 'builders' is used for the startup order of components
+ ProjectConfigurator projectConfigurator,
+ ProjectFilter projectFilter) {
this.projectReactor = projectReactor;
this.configurator = projectConfigurator;
this.projectFilter = projectFilter;
@@ -62,7 +61,7 @@ public class ProjectTree {
this.configurator = configurator;
}
- public void start() throws IOException {
+ public void start() {
doStart(projectReactor.getProjects());
}
@@ -93,7 +92,7 @@ public class ProjectTree {
}
void applyExclusions() {
- for (Iterator<Project> it = projects.iterator(); it.hasNext(); ) {
+ for (Iterator<Project> it = projects.iterator(); it.hasNext();) {
Project project = it.next();
if (projectFilter.isExcluded(project)) {
project.setExcluded(true);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
index d7e59ef760b..1cdb7b9217c 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
@@ -109,7 +109,6 @@ public class JdbcDriverHolder {
Class<?> lpClass = defineClass("org.sonar.batch.bootstrap.JdbcLeakPrevention", classBytes, 0, offset, this.getClass().getProtectionDomain());
Object obj = lpClass.newInstance();
- @SuppressWarnings("unchecked")
List<String> driverNames = (List<String>) obj.getClass().getMethod("clearJdbcDriverRegistrations").invoke(obj);
for (String name : driverNames) {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java b/sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java
index 3588c583e23..65773cad905 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java
@@ -19,12 +19,12 @@
*/
package org.sonar.batch;
-import org.apache.commons.io.FileUtils;
import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
+import org.sonar.test.TestUtils;
import java.io.File;
@@ -34,7 +34,7 @@ import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
public class DefaultProjectFileSystem2Test {
@Test
public void shouldIgnoreInexistingSourceDirs() {
- File exists = FileUtils.toFile(getClass().getResource("/org/sonar/batch/DefaultProjectFileSystem2Test/shouldIgnoreInexistingSourceDirs"));
+ File exists = TestUtils.getResource("/org/sonar/batch/DefaultProjectFileSystem2Test/shouldIgnoreInexistingSourceDirs");
File notExists = new File("target/unknown");
ProjectDefinition definition = ProjectDefinition.create().addSourceDirs(exists, notExists);
@@ -42,6 +42,5 @@ public class DefaultProjectFileSystem2Test {
DefaultProjectFileSystem2 fs = new DefaultProjectFileSystem2(new Project("foo"), new Languages(), definition);
assertThat(fs.getSourceDirs().size(), Is.is(1));
assertThat(fs.getSourceDirs(), hasItem(exists));
-
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java
index fe3cf025e9c..38abbf99fd0 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java
@@ -19,19 +19,6 @@
*/
package org.sonar.batch;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringReader;
-import java.net.URISyntaxException;
-import java.util.Arrays;
-import java.util.Properties;
-
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -41,6 +28,20 @@ import org.hamcrest.core.Is;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.test.TestUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Properties;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
public class MavenProjectConverterTest {
@@ -96,7 +97,7 @@ public class MavenProjectConverterTest {
@Test
public void moduleNameShouldEqualArtifactId() throws Exception {
- File rootDir = FileUtils.toFile(getClass().getResource("/org/sonar/batch/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/"));
+ File rootDir = TestUtils.getResource("/org/sonar/batch/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/");
MavenProject parent = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true);
MavenProject module1 = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false);
MavenProject module2 = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false);
@@ -117,7 +118,7 @@ public class MavenProjectConverterTest {
@Test
public void moduleNameDifferentThanArtifactId() throws Exception {
- File rootDir = FileUtils.toFile(getClass().getResource("/org/sonar/batch/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/"));
+ File rootDir = TestUtils.getResource("/org/sonar/batch/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/");
MavenProject parent = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true);
MavenProject module1 = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false);
MavenProject module2 = loadPom("/org/sonar/batch/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false);
@@ -138,7 +139,7 @@ public class MavenProjectConverterTest {
@Test
public void testSingleProjectWithoutModules() throws Exception {
- File rootDir = FileUtils.toFile(getClass().getResource("/org/sonar/batch/MavenProjectConverterTest/singleProjectWithoutModules/"));
+ File rootDir = TestUtils.getResource("/org/sonar/batch/MavenProjectConverterTest/singleProjectWithoutModules/");
MavenProject pom = loadPom("/org/sonar/batch/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true);
ProjectDefinition rootDef = MavenProjectConverter.convert(Arrays.asList(pom), pom);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java b/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
index 24f913239bd..48d36520ff5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
@@ -19,101 +19,98 @@
*/
package org.sonar.batch;
-import org.apache.commons.configuration.PropertiesConfiguration;
-import org.apache.maven.project.MavenProject;
import org.junit.Ignore;
-import org.sonar.api.resources.Project;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
@Ignore
public class ProjectTreeTest extends AbstractDbUnitTestCase {
-// @Test
-// public void keyIncludesBranch() throws IOException, XmlPullParserException, URISyntaxException {
-// MavenProject pom = loadProject("/org/sonar/batch/ProjectTreeTest/keyIncludesBranch/pom.xml", true);
-//
-// ProjectTree tree = new ProjectTree(newConfigurator(), Arrays.asList(pom));
-// tree.start();
-//
-// assertThat(tree.getRootProject().getKey(), is("org.test:project:BRANCH-1.X"));
-// assertThat(tree.getRootProject().getName(), is("Project BRANCH-1.X"));
-// }
-//
-// @Test
-// public void doNotSkipAnyModules() {
-// Project foo = newProjectWithArtifactId("root");
-// Project bar = newProjectWithArtifactId("sub1");
-// Project baz = newProjectWithArtifactId("sub2");
-//
-// ProjectTree tree = new ProjectTree(Arrays.asList(foo, bar, baz));
-// tree.applyExclusions();
-//
-// assertThat(tree.getProjects().size(), is(3));
-// }
-//
-// @Test
-// public void skipModule() throws IOException {
-// Project root = newProjectWithArtifactId("root");
-// root.getConfiguration().setProperty("sonar.skippedModules", "sub1");
-// Project sub1 = newProjectWithArtifactId("sub1");
-// Project sub2 = newProjectWithArtifactId("sub2");
-//
-// ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
-// tree.applyExclusions();
-//
-// assertThat(tree.getProjects().size(), is(2));
-// assertThat(tree.getProjects(), hasItem(root));
-// assertThat(tree.getProjects(), hasItem(sub2));
-// }
-//
-// @Test
-// public void skipModules() {
-// Project root = newProjectWithArtifactId("root");
-// root.getConfiguration().setProperty("sonar.skippedModules", "sub1,sub2");
-// Project sub1 = newProjectWithArtifactId("sub1");
-// Project sub2 = newProjectWithArtifactId("sub2");
-//
-// ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
-// tree.applyExclusions();
-//
-// assertThat(tree.getProjects().size(), is(1));
-// assertThat(tree.getProjects(), hasItem(root));
-// }
-//
-// @Test
-// public void includeModules() {
-// Project root = newProjectWithArtifactId("root");
-// root.getConfiguration().setProperty("sonar.includedModules", "sub1,sub2");
-// Project sub1 = newProjectWithArtifactId("sub1");
-// Project sub2 = newProjectWithArtifactId("sub2");
-//
-// ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
-// tree.applyExclusions();
-//
-// assertThat(tree.getProjects().size(), is(2));
-// assertThat(tree.getProjects(), hasItem(sub1));
-// assertThat(tree.getProjects(), hasItem(sub2));
-// }
-//
-// @Test
-// public void skippedModulesTakePrecedenceOverIncludedModules() {
-// Project root = newProjectWithArtifactId("root");
-// root.getConfiguration().setProperty("sonar.includedModules", "sub1,sub2");
-// root.getConfiguration().setProperty("sonar.skippedModules", "sub1");
-// Project sub1 = newProjectWithArtifactId("sub1");
-// Project sub2 = newProjectWithArtifactId("sub2");
-//
-// ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
-// tree.applyExclusions();
-//
-// assertThat(tree.getProjects().size(), is(1));
-// assertThat(tree.getProjects(), hasItem(sub2));
-// }
+ // @Test
+ // public void keyIncludesBranch() throws IOException, XmlPullParserException, URISyntaxException {
+ // MavenProject pom = loadProject("/org/sonar/batch/ProjectTreeTest/keyIncludesBranch/pom.xml", true);
+ //
+ // ProjectTree tree = new ProjectTree(newConfigurator(), Arrays.asList(pom));
+ // tree.start();
+ //
+ // assertThat(tree.getRootProject().getKey(), is("org.test:project:BRANCH-1.X"));
+ // assertThat(tree.getRootProject().getName(), is("Project BRANCH-1.X"));
+ // }
+ //
+ // @Test
+ // public void doNotSkipAnyModules() {
+ // Project foo = newProjectWithArtifactId("root");
+ // Project bar = newProjectWithArtifactId("sub1");
+ // Project baz = newProjectWithArtifactId("sub2");
+ //
+ // ProjectTree tree = new ProjectTree(Arrays.asList(foo, bar, baz));
+ // tree.applyExclusions();
+ //
+ // assertThat(tree.getProjects().size(), is(3));
+ // }
+ //
+ // @Test
+ // public void skipModule() throws IOException {
+ // Project root = newProjectWithArtifactId("root");
+ // root.getConfiguration().setProperty("sonar.skippedModules", "sub1");
+ // Project sub1 = newProjectWithArtifactId("sub1");
+ // Project sub2 = newProjectWithArtifactId("sub2");
+ //
+ // ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
+ // tree.applyExclusions();
+ //
+ // assertThat(tree.getProjects().size(), is(2));
+ // assertThat(tree.getProjects(), hasItem(root));
+ // assertThat(tree.getProjects(), hasItem(sub2));
+ // }
+ //
+ // @Test
+ // public void skipModules() {
+ // Project root = newProjectWithArtifactId("root");
+ // root.getConfiguration().setProperty("sonar.skippedModules", "sub1,sub2");
+ // Project sub1 = newProjectWithArtifactId("sub1");
+ // Project sub2 = newProjectWithArtifactId("sub2");
+ //
+ // ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
+ // tree.applyExclusions();
+ //
+ // assertThat(tree.getProjects().size(), is(1));
+ // assertThat(tree.getProjects(), hasItem(root));
+ // }
+ //
+ // @Test
+ // public void includeModules() {
+ // Project root = newProjectWithArtifactId("root");
+ // root.getConfiguration().setProperty("sonar.includedModules", "sub1,sub2");
+ // Project sub1 = newProjectWithArtifactId("sub1");
+ // Project sub2 = newProjectWithArtifactId("sub2");
+ //
+ // ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
+ // tree.applyExclusions();
+ //
+ // assertThat(tree.getProjects().size(), is(2));
+ // assertThat(tree.getProjects(), hasItem(sub1));
+ // assertThat(tree.getProjects(), hasItem(sub2));
+ // }
+ //
+ // @Test
+ // public void skippedModulesTakePrecedenceOverIncludedModules() {
+ // Project root = newProjectWithArtifactId("root");
+ // root.getConfiguration().setProperty("sonar.includedModules", "sub1,sub2");
+ // root.getConfiguration().setProperty("sonar.skippedModules", "sub1");
+ // Project sub1 = newProjectWithArtifactId("sub1");
+ // Project sub2 = newProjectWithArtifactId("sub2");
+ //
+ // ProjectTree tree = new ProjectTree(Arrays.asList(root, sub1, sub2));
+ // tree.applyExclusions();
+ //
+ // assertThat(tree.getProjects().size(), is(1));
+ // assertThat(tree.getProjects(), hasItem(sub2));
+ // }
- private Project newProjectWithArtifactId(String artifactId) {
- MavenProject pom = new MavenProject();
- pom.setArtifactId(artifactId);
- return new Project("org.example:" + artifactId).setPom(pom).setConfiguration(new PropertiesConfiguration());
- }
+ // private Project newProjectWithArtifactId(String artifactId) {
+ // MavenProject pom = new MavenProject();
+ // pom.setArtifactId(artifactId);
+ // return new Project("org.example:" + artifactId).setPom(pom).setConfiguration(new PropertiesConfiguration());
+ // }
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java b/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
index 491d120f39b..b0d593f78a2 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
@@ -23,15 +23,13 @@ import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
-import java.text.ParseException;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
public class ServerMetadataTest {
@Test
- public void testLoadProperties() throws ParseException {
+ public void testLoadProperties() {
Settings settings = new Settings();
settings.setProperty(CoreProperties.SERVER_ID, "123");
settings.setProperty(CoreProperties.SERVER_VERSION, "2.2");
@@ -51,7 +49,7 @@ public class ServerMetadataTest {
* The maven plugin fails if the property sonar.host.url ends with a slash
*/
@Test
- public void urlMustNotEndWithSlash() throws ParseException {
+ public void urlMustNotEndWithSlash() {
Settings settings = new Settings();
settings.setProperty("sonar.host.url", "http://localhost:80/");
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
index c700aa2af46..8fa44b14fbb 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
@@ -45,7 +45,7 @@ public class BatchExtensionInstallerTest {
Map<PluginMetadata, Plugin> result = Maps.newHashMap();
result.put(METADATA,
new SonarPlugin() {
- public List getExtensions() {
+ public List<Class> getExtensions() {
return Arrays.asList(classes);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index bb50e80b9a3..944eb90977e 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -27,6 +27,7 @@ import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.core.plugins.RemotePlugin;
+import org.sonar.test.TestUtils;
import java.io.File;
import java.io.IOException;
@@ -45,7 +46,7 @@ public class BatchPluginRepositoryTest {
@After
public void tearDown() {
- if (repository!=null) {
+ if (repository != null) {
repository.stop();
}
}
@@ -105,7 +106,8 @@ public class BatchPluginRepositoryTest {
assertThat(repository.getPlugin("checkstyle"), not(nullValue()));
assertThat(repository.getMetadata().size(), Matchers.is(1));
assertThat(repository.getMetadata("checkstyle").getName(), Matchers.is("Checkstyle"));
- assertThat(repository.getMetadata("checkstyle").getDeployedFiles().size(), Matchers.is(5)); // plugin + 3 dependencies + 1 deprecated extension
+ assertThat(repository.getMetadata("checkstyle").getDeployedFiles().size(), Matchers.is(5)); // plugin + 3 dependencies + 1 deprecated
+ // extension
}
@Test
@@ -128,9 +130,9 @@ public class BatchPluginRepositoryTest {
}
private List<File> copyFiles(String... filenames) throws IOException {
- List files = Lists.newArrayList();
+ List<File> files = Lists.newArrayList();
for (String filename : filenames) {
- File file = FileUtils.toFile(getClass().getResource("/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename));
+ File file = TestUtils.getResource("/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename);
File tempDir = new File("target/test-tmp/BatchPluginRepositoryTest");
FileUtils.forceMkdir(tempDir);
FileUtils.copyFileToDirectory(file, tempDir);
@@ -139,7 +141,6 @@ public class BatchPluginRepositoryTest {
return files;
}
-
@Test
public void shouldAlwaysAcceptIfNoWhiteListAndBlackList() {
repository = new BatchPluginRepository(mock(ArtifactDownloader.class), new Settings());
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
index a7147e1a37d..374dc7e8f92 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
@@ -19,10 +19,16 @@
*/
package org.sonar.batch.bootstrap;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import org.apache.maven.project.MavenProject;
import org.junit.Test;
-import org.sonar.api.*;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Extension;
+import org.sonar.api.Plugin;
+import org.sonar.api.ServerExtension;
+import org.sonar.api.SonarPlugin;
import org.sonar.api.batch.CoverageExtension;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.SupportedEnvironment;
@@ -31,11 +37,12 @@ import org.sonar.api.resources.Java;
import org.sonar.api.resources.Project;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -59,8 +66,8 @@ public class ProjectExtensionInstallerTest {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
Map<String, Plugin> pluginsMap = Maps.newHashMap();
pluginsMap.put("fooPlugin", new SonarPlugin() {
- public List getExtensions() {
- return Arrays.asList(BatchService.class, ProjectService.class, ServerService.class);
+ public List<Class<? extends Extension>> getExtensions() {
+ return ImmutableList.of(BatchService.class, ProjectService.class, ServerService.class);
}
});
when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
@@ -79,8 +86,8 @@ public class ProjectExtensionInstallerTest {
BatchPluginRepository pluginRepository = mock(BatchPluginRepository.class);
Map<String, Plugin> pluginsMap = Maps.newHashMap();
pluginsMap.put("fooPlugin", new SonarPlugin() {
- public List getExtensions() {
- return Arrays.asList(MavenService.class, BuildToolService.class);
+ public List<Class<? extends BatchExtension>> getExtensions() {
+ return ImmutableList.of(MavenService.class, BuildToolService.class);
}
});
when(pluginRepository.getPluginsByKey()).thenReturn(pluginsMap);
@@ -123,7 +130,6 @@ public class ProjectExtensionInstallerTest {
}
-
@SupportedEnvironment("maven")
public static class MavenService implements BatchExtension {
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
index bc6ca178804..c07ca958198 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
@@ -40,21 +40,21 @@ public class TempDirectoriesTest {
}
@After
- public void after() throws IOException {
+ public void after() {
if (tempDirectories != null) {
tempDirectories.stop();
}
}
@Test
- public void shouldCreateRoot() throws IOException {
+ public void shouldCreateRoot() {
assertNotNull(tempDirectories.getRoot());
assertThat(tempDirectories.getRoot().exists(), is(true));
assertThat(tempDirectories.getRoot().isDirectory(), is(true));
}
@Test
- public void shouldCreateDirectory() throws IOException {
+ public void shouldCreateDirectory() {
File findbugsDir = tempDirectories.getDir("findbugs");
assertNotNull(findbugsDir);
assertThat(findbugsDir.exists(), is(true));
@@ -63,13 +63,13 @@ public class TempDirectoriesTest {
}
@Test
- public void shouldStopAndDeleteDirectory() throws IOException {
+ public void shouldStopAndDeleteDirectory() {
File root = tempDirectories.getRoot();
File findbugsDir = tempDirectories.getDir("findbugs");
assertThat(findbugsDir.exists(), is(true));
tempDirectories.stop();
-
+
assertThat(root.exists(), is(false));
assertThat(findbugsDir.exists(), is(false));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
index 69c7bc6e6cb..391fc551a44 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
@@ -40,7 +40,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
@Test
- public void shouldGetNextSnapshot() throws ParseException {
+ public void shouldGetNextSnapshot() {
setupData("shared");
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
@@ -50,7 +50,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
}
@Test
- public void shouldIgnoreUnprocessedSnapshots() throws ParseException {
+ public void shouldIgnoreUnprocessedSnapshots() {
setupData("shared");
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
@@ -60,7 +60,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
}
@Test
- public void shouldNotFindSelf() throws ParseException {
+ public void shouldNotFindSelf() {
setupData("shouldNotFindSelf");
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1009); // 2008-11-16
@@ -79,7 +79,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
newSnapshot(2, "2010-10-03"),// -2 days
newSnapshot(3, "2010-10-08"),// +3 days
newSnapshot(4, "2010-10-12") // + 7 days
- );
+ );
assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(2));
}
@@ -93,7 +93,7 @@ public class PastSnapshotFinderByDaysTest extends AbstractDbUnitTestCase {
newSnapshot(2, "2010-10-01"),// -4 days
newSnapshot(3, "2010-10-08"),// +3 days
newSnapshot(4, "2010-10-12") // + 7 days
- );
+ );
assertThat(PastSnapshotFinderByDays.getNearestToTarget(snapshots, current, 15).getId(), is(3));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java
index 7bf1c050d2e..e3f12cde851 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java
@@ -19,20 +19,18 @@
*/
package org.sonar.batch.components;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
import org.sonar.api.database.model.Snapshot;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import java.text.ParseException;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTestCase {
@Test
- public void shouldFindPreviousAnalysis() throws ParseException {
+ public void shouldFindPreviousAnalysis() {
setupData("shouldFindPreviousAnalysis");
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
@@ -43,7 +41,7 @@ public class PastSnapshotFinderByPreviousAnalysisTest extends AbstractDbUnitTest
}
@Test
- public void shouldReturnPastSnapshotEvenWhenNoPreviousAnalysis() throws ParseException {
+ public void shouldReturnPastSnapshotEvenWhenNoPreviousAnalysis() {
setupData("shouldNotFindPreviousAnalysis");
Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1010);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
index 54575f1a905..2ab6d29a945 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
@@ -37,7 +37,11 @@ import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PastSnapshotFinderTest {
@@ -100,7 +104,7 @@ public class PastSnapshotFinderTest {
}
@Test
- public void shouldNotFindByDate() throws ParseException {
+ public void shouldNotFindByDate() {
when(finderByDate.findByDate((Snapshot) anyObject(), (Date) anyObject())).thenReturn(null);
PastSnapshot variationSnapshot = finder.find(null, 2, "2010-05-18");
@@ -160,7 +164,10 @@ public class PastSnapshotFinderTest {
@Test
public void shouldNotFailIfUnknownFormat() {
- when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot())); // should not be called
+ when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot())); // should
+ // not
+ // be
+ // called
assertNull(finder.find(null, 2, "foooo"));
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
index c85ca8a895f..03e580d68f1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
@@ -60,7 +60,6 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
moduleB1.setParent(moduleB);
}
-
@Test
public void shouldSaveNewProject() {
setupData("shared");
@@ -68,11 +67,11 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(singleProject, null);
- checkTablesWithExcludedColumns("shouldSaveNewProject", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldSaveNewProject", new String[] {"build_date"}, "projects", "snapshots");
}
@Test
- public void shouldSaveNewMultiModulesProject() throws ParseException {
+ public void shouldSaveNewMultiModulesProject() {
setupData("shared");
ResourcePersister persister = new DefaultResourcePersister(getSession());
@@ -81,7 +80,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
persister.saveProject(moduleB, multiModuleProject);
persister.saveProject(moduleB1, moduleB);
- checkTablesWithExcludedColumns("shouldSaveNewMultiModulesProject", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldSaveNewMultiModulesProject", new String[] {"build_date"}, "projects", "snapshots");
}
@Test
@@ -93,7 +92,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
persister.saveResource(singleProject, new JavaPackage("org.foo").setEffectiveKey("foo:org.foo"));
// check that the directory is attached to the project
- checkTablesWithExcludedColumns("shouldSaveNewDirectory", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldSaveNewDirectory", new String[] {"build_date"}, "projects", "snapshots");
}
@Test
@@ -106,7 +105,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
persister.saveResource(singleProject, new Library("junit:junit", "4.8.2").setEffectiveKey("junit:junit"));// do nothing, already saved
persister.saveResource(singleProject, new Library("junit:junit", "3.2").setEffectiveKey("junit:junit"));
- checkTablesWithExcludedColumns("shouldSaveNewLibrary", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldSaveNewLibrary", new String[] {"build_date"}, "projects", "snapshots");
}
@Test
@@ -134,7 +133,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
singleProject.setDescription("new description");
persister.saveProject(singleProject, null);
- checkTablesWithExcludedColumns("shouldUpdateExistingResource", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldUpdateExistingResource", new String[] {"build_date"}, "projects", "snapshots");
}
// SONAR-1700
@@ -145,7 +144,7 @@ public class DefaultResourcePersisterTest extends AbstractDbUnitTestCase {
ResourcePersister persister = new DefaultResourcePersister(getSession());
persister.saveProject(singleProject, null);
- checkTablesWithExcludedColumns("shouldRemoveRootIndexIfResourceIsProject", new String[]{"build_date"}, "projects", "snapshots");
+ checkTablesWithExcludedColumns("shouldRemoveRootIndexIfResourceIsProject", new String[] {"build_date"}, "projects", "snapshots");
}
}