summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java16
-rw-r--r--plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java27
-rw-r--r--plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java3
-rw-r--r--plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java45
-rw-r--r--plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java28
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java2
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java22
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java31
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java37
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java3
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java13
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java23
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java11
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java13
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java3
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java18
-rw-r--r--plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java42
-rw-r--r--plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java3
-rw-r--r--plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java12
-rw-r--r--plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java27
-rw-r--r--plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java18
-rw-r--r--plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java7
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java4
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java24
-rw-r--r--plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java9
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java14
-rw-r--r--plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java26
-rw-r--r--plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java19
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java25
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java2
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java1
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java23
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java29
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java6
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java12
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java1
-rw-r--r--plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java9
-rw-r--r--plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java18
-rw-r--r--plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java4
-rw-r--r--sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java6
-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
-rw-r--r--sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java8
-rw-r--r--sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java30
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java5
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java9
-rw-r--r--sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java10
-rw-r--r--sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java3
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java50
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java29
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java8
-rw-r--r--sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java1
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java18
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java24
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java19
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java26
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java10
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java23
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java30
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java13
-rw-r--r--sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java10
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java8
-rw-r--r--sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java26
-rw-r--r--sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java16
-rw-r--r--sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java5
-rw-r--r--sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java20
-rw-r--r--sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java5
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java11
-rw-r--r--sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java32
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java2
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java2
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java1
92 files changed, 761 insertions, 716 deletions
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
index 803dfc1ddf9..550c7e4b1f4 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
@@ -37,7 +37,11 @@ import org.sonar.api.resources.Java;
import org.sonar.api.resources.ProjectFileSystem;
import org.sonar.api.utils.SonarException;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
@@ -56,10 +60,10 @@ public class CheckstyleConfiguration implements BatchExtension {
private static final Logger LOG = LoggerFactory.getLogger(CheckstyleConfiguration.class);
public static final String PROPERTY_GENERATE_XML = "sonar.checkstyle.generateXml";
- private CheckstyleProfileExporter confExporter;
- private RulesProfile profile;
- private Settings conf;
- private ProjectFileSystem fileSystem;
+ private final CheckstyleProfileExporter confExporter;
+ private final RulesProfile profile;
+ private final Settings conf;
+ private final ProjectFileSystem fileSystem;
public CheckstyleConfiguration(Settings conf, CheckstyleProfileExporter confExporter, RulesProfile profile, ProjectFileSystem fileSystem) {
this.conf = conf;
@@ -96,7 +100,7 @@ public class CheckstyleConfiguration implements BatchExtension {
return null;
}
- public com.puppycrawl.tools.checkstyle.api.Configuration getCheckstyleConfiguration() throws IOException, CheckstyleException {
+ public com.puppycrawl.tools.checkstyle.api.Configuration getCheckstyleConfiguration() throws CheckstyleException {
File xmlConfig = getXMLDefinitionFile();
LOG.info("Checkstyle configuration: " + xmlConfig.getAbsolutePath());
diff --git a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
index 9bba008989b..b81a8454578 100644
--- a/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
+++ b/plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
@@ -19,12 +19,13 @@
*/
package org.sonar.plugins.checkstyle;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.Extension;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
import org.sonar.api.SonarPlugin;
-import java.util.Arrays;
import java.util.List;
@Properties({
@@ -39,17 +40,17 @@ import java.util.List;
type = PropertyType.TEXT)})
public final class CheckstylePlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(
- CheckstyleSensor.class,
- CheckstyleConfiguration.class,
- CheckstyleExecutor.class,
- CheckstyleAuditListener.class,
- CheckstyleProfileExporter.class,
- CheckstyleProfileImporter.class,
- CheckstyleRuleRepository.class,
- SonarWayProfile.class,
- SunConventionsProfile.class,
- SonarWayWithFindbugsProfile.class);
+ public List<Class<? extends Extension>> getExtensions() {
+ return ImmutableList.of(
+ CheckstyleSensor.class,
+ CheckstyleConfiguration.class,
+ CheckstyleExecutor.class,
+ CheckstyleAuditListener.class,
+ CheckstyleProfileExporter.class,
+ CheckstyleProfileImporter.class,
+ CheckstyleRuleRepository.class,
+ SonarWayProfile.class,
+ SunConventionsProfile.class,
+ SonarWayWithFindbugsProfile.class);
}
}
diff --git a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
index 8ab95ac7f9a..69831487119 100644
--- a/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
+++ b/plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
@@ -21,7 +21,6 @@ package org.sonar.plugins.checkstyle;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
-import org.sonar.api.config.Settings;
import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.test.MavenTestUtils;
@@ -29,8 +28,6 @@ import org.sonar.api.test.MavenTestUtils;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
-import java.util.Locale;
-
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
diff --git a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java
index fcea73baa5e..222c2c5ac77 100644
--- a/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java
+++ b/plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java
@@ -19,32 +19,35 @@
*/
package org.sonar.plugins.cobertura;
-import org.sonar.api.*;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.SonarPlugin;
-import java.util.ArrayList;
import java.util.List;
@Properties({
- @Property(
- key = CoreProperties.COBERTURA_REPORT_PATH_PROPERTY,
- name = "Report path",
- description = "Path (absolute or relative) to Cobertura xml report file.",
- project = true,
- global = false),
- @Property(
- key = CoreProperties.COBERTURA_MAXMEM_PROPERTY,
- defaultValue = CoreProperties.COBERTURA_MAXMEM_DEFAULT_VALUE,
- name = "Maxmem",
- description = "Maximum memory to pass to JVM of Cobertura processes",
- project = true,
- global = true) })
+ @Property(
+ key = CoreProperties.COBERTURA_REPORT_PATH_PROPERTY,
+ name = "Report path",
+ description = "Path (absolute or relative) to Cobertura xml report file.",
+ project = true,
+ global = false),
+ @Property(
+ key = CoreProperties.COBERTURA_MAXMEM_PROPERTY,
+ defaultValue = CoreProperties.COBERTURA_MAXMEM_DEFAULT_VALUE,
+ name = "Maxmem",
+ description = "Maximum memory to pass to JVM of Cobertura processes",
+ project = true,
+ global = true)})
public class CoberturaPlugin extends SonarPlugin {
- public List<Class<? extends Extension>> getExtensions() {
- List<Class<? extends Extension>> list = new ArrayList<Class<? extends Extension>>();
- list.add(CoberturaSensor.class);
- list.add(CoberturaMavenPluginHandler.class);
- list.add(CoberturaMavenInitializer.class);
- return list;
+ public List<Class<? extends BatchExtension>> getExtensions() {
+ return ImmutableList.of(
+ CoberturaSensor.class,
+ CoberturaMavenPluginHandler.class,
+ CoberturaMavenInitializer.class);
}
}
diff --git a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
index dd37f433f62..83db39159c6 100644
--- a/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
+++ b/plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
@@ -19,26 +19,36 @@
*/
package org.sonar.plugins.cobertura;
-import static org.hamcrest.CoreMatchers.is;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.ProjectFileSystem;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.test.IsMeasure;
import org.sonar.api.test.IsResource;
import java.io.File;
import java.net.URISyntaxException;
+import static org.hamcrest.CoreMatchers.is;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyDouble;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class CoberturaSensorTest {
private SensorContext context;
@@ -51,7 +61,7 @@ public class CoberturaSensorTest {
}
@Test
- public void shouldNotFailIfReportNotSpecifiedOrNotFound() throws URISyntaxException {
+ public void shouldNotFailIfReportNotSpecifiedOrNotFound() {
ProjectFileSystem pfs = mock(ProjectFileSystem.class);
when(pfs.resolvePath(anyString()))
.thenReturn(new File("notFound.xml"));
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
index 71c09d25209..29764d34fdc 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
@@ -223,7 +223,7 @@ import java.util.List;
public final class CorePlugin extends SonarPlugin {
@SuppressWarnings({"rawtypes", "unchecked"})
- public List getExtensions() {
+ public List<Class<? extends Extension>> getExtensions() {
List extensions = Lists.newLinkedList();
extensions.add(DefaultResourceTypes.class);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java
index 4e2d41888ab..f6ccdb668b3 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java
@@ -19,13 +19,8 @@
*/
package org.sonar.plugins.core.sensors;
-import org.dbunit.dataset.DataSetException;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.Event;
import org.sonar.api.batch.TimeMachine;
@@ -41,6 +36,16 @@ import org.sonar.api.test.ProjectTestBuilder;
import java.util.Arrays;
import java.util.Date;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class GenerateAlertEventsTest {
private GenerateAlertEvents decorator;
private DecoratorContext context;
@@ -113,14 +118,14 @@ public class GenerateAlertEventsTest {
}
@Test
- public void shouldNotCreateEventWhenNoAlertStatus() throws DataSetException {
+ public void shouldNotCreateEventWhenNoAlertStatus() {
decorator.decorate(project, context);
verify(context, never()).createEvent(anyString(), anyString(), anyString(), (Date) isNull());
}
@Test
- public void shouldNotCreateEventWhenSameLevel() throws DataSetException {
+ public void shouldNotCreateEventWhenSameLevel() {
when(timeMachine.getMeasures((TimeMachineQuery) anyObject())).thenReturn(Arrays.asList(newAlertStatus(Metric.Level.ERROR, "desc")));
when(context.getMeasure(CoreMetrics.ALERT_STATUS)).thenReturn(newAlertStatus(Metric.Level.ERROR, "desc"));
@@ -130,7 +135,7 @@ public class GenerateAlertEventsTest {
}
@Test
- public void shouldNotCreateEventIfNoMoreAlertStatus() throws DataSetException {
+ public void shouldNotCreateEventIfNoMoreAlertStatus() {
when(timeMachine.getMeasures((TimeMachineQuery) anyObject())).thenReturn(Arrays.asList(newAlertStatus(Metric.Level.ERROR, "desc")));
when(context.getMeasure(CoreMetrics.ALERT_STATUS)).thenReturn(null);
@@ -139,7 +144,6 @@ public class GenerateAlertEventsTest {
verify(context, never()).createEvent(anyString(), anyString(), anyString(), (Date) isNull());
}
-
private Measure newAlertStatus(Metric.Level level, String label) {
Measure measure = new Measure(CoreMetrics.ALERT_STATUS, level);
measure.setAlertStatus(level);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java
index f0626571a47..f2b885fb65d 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java
@@ -19,11 +19,6 @@
*/
package org.sonar.plugins.core.sensors;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
-
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.Event;
@@ -36,11 +31,23 @@ import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
-import java.text.ParseException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
public class ProfileEventsSensorTest {
private Project project;
@@ -61,7 +68,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldDoNothingIfNoProfile() throws ParseException {
+ public void shouldDoNothingIfNoProfile() {
ProfileEventsSensor sensor = new ProfileEventsSensor(null, null);
sensor.analyse(project, context);
@@ -70,7 +77,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldDoNothingIfNoProfileChange() throws ParseException {
+ public void shouldDoNothingIfNoProfileChange() {
RulesProfile profile = mockProfileWithVersion(1);
TimeMachine timeMachine = mockTM(project, 22.0, "Foo", 1.0); // Same profile, same version
ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
@@ -81,7 +88,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldCreateEventIfProfileChange() throws ParseException {
+ public void shouldCreateEventIfProfileChange() {
RulesProfile profile = mockProfileWithVersion(1);
TimeMachine timeMachine = mockTM(project, 21.0, "Bar", 1.0); // Different profile
ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
@@ -95,7 +102,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldCreateEventIfProfileVersionChange() throws ParseException {
+ public void shouldCreateEventIfProfileVersionChange() {
RulesProfile profile = mockProfileWithVersion(2);
TimeMachine timeMachine = mockTM(project, 22.0, "Foo", 1.0); // Same profile, different version
ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
@@ -109,7 +116,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldNotCreateEventIfFirstAnalysis() throws ParseException {
+ public void shouldNotCreateEventIfFirstAnalysis() {
RulesProfile profile = mockProfileWithVersion(2);
TimeMachine timeMachine = mockTM(project, null, null);
ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
@@ -120,7 +127,7 @@ public class ProfileEventsSensorTest {
}
@Test
- public void shouldCreateEventIfFirstAnalysisWithVersionsAndVersionMoreThan1() throws ParseException {
+ public void shouldCreateEventIfFirstAnalysisWithVersionsAndVersionMoreThan1() {
RulesProfile profile = mockProfileWithVersion(2);
TimeMachine timeMachine = mockTM(project, 22.0, "Foo", null);
ProfileEventsSensor sensor = new ProfileEventsSensor(profile, timeMachine);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java
index 1c8db23ba19..65af02fcab2 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java
@@ -19,6 +19,15 @@
*/
package org.sonar.plugins.core.sensors;
+import com.google.common.collect.Lists;
+import org.junit.Test;
+import org.sonar.api.batch.Event;
+import org.sonar.api.batch.SensorContext;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
+
+import java.util.Date;
+
import static org.mockito.Matchers.anyObject;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
@@ -28,23 +37,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-
-import org.junit.Test;
-import org.sonar.api.batch.Event;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-
public class VersionEventsSensorTest {
- private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
- private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMdd HH:mm");
-
@Test
public void shouldDoNothingIfNoVersion() {
VersionEventsSensor sensor = new VersionEventsSensor();
@@ -83,7 +77,7 @@ public class VersionEventsSensorTest {
Project project = mock(Project.class);
when(project.getAnalysisVersion()).thenReturn("1.5-SNAPSHOT");
- when(context.getEvents(project)).thenReturn(new ArrayList(Arrays.asList(sameVersionEvent, otherEvent, anotherEvent)));
+ when(context.getEvents(project)).thenReturn(Lists.newArrayList(sameVersionEvent, otherEvent, anotherEvent));
sensor.analyse(project, context);
@@ -99,7 +93,7 @@ public class VersionEventsSensorTest {
SensorContext context = mock(SensorContext.class);
Project project = mock(Project.class);
when(project.getAnalysisVersion()).thenReturn("1.5");
- when(context.getEvents(project)).thenReturn(new ArrayList(Arrays.asList(snapshotVersion, otherEvent)));
+ when(context.getEvents(project)).thenReturn(Lists.newArrayList(snapshotVersion, otherEvent));
VersionEventsSensor sensor = new VersionEventsSensor();
sensor.analyse(project, context);
@@ -114,13 +108,4 @@ public class VersionEventsSensorTest {
when(event.getName()).thenReturn(version);
return event;
}
-
- private Event mockEvent(String name, String yyyyMMdd) throws ParseException {
- Event event = mock(Event.class);
- when(event.isVersionCategory()).thenReturn(false);
- when(event.isLinkedToSnapshot()).thenReturn(false);
- when(event.getName()).thenReturn(name);
- when(event.getDate()).thenReturn(dateFormat.parse(yyyyMMdd));
- return event;
- }
}
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
index 36a0abc05a7..da8bc44ac4c 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
@@ -26,7 +26,6 @@ import org.sonar.batch.components.PastSnapshot;
import org.sonar.batch.components.TimeMachineConfiguration;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import java.text.ParseException;
import java.util.Arrays;
import static org.mockito.Mockito.mock;
@@ -35,7 +34,7 @@ import static org.mockito.Mockito.when;
public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCase {
@Test
- public void shouldSaveConfigurationInSnapshotsTable() throws ParseException {
+ public void shouldSaveConfigurationInSnapshotsTable() {
setupData("shared");
TimeMachineConfiguration conf = mock(TimeMachineConfiguration.class);
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java
index 7ec500b954c..911f66ff443 100644
--- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java
+++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java
@@ -28,12 +28,13 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.DateUtils;
-import java.text.ParseException;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -41,10 +42,10 @@ import static org.mockito.Mockito.when;
public class ViolationTrackingDecoratorTest {
private ViolationTrackingDecorator decorator;
- private Date analysisDate = DateUtils.parseDate("2010-12-25");
+ private final Date analysisDate = DateUtils.parseDate("2010-12-25");
@Before
- public void setUp() throws ParseException {
+ public void setUp() {
Project project = mock(Project.class);
when(project.getAnalysisDate()).thenReturn(analysisDate);
decorator = new ViolationTrackingDecorator(project, null, null);
@@ -183,7 +184,7 @@ public class ViolationTrackingDecoratorTest {
Violation newViolation = newViolation("message", 1, 50, "checksum");
assertThat(newViolation.getCreatedAt(), nullValue());
- Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Collections.<RuleFailureModel>emptyList());
+ Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Collections.<RuleFailureModel> emptyList());
assertThat(mapping.size(), is(0));
assertThat(newViolation.getCreatedAt(), is(analysisDate));
assertThat(newViolation.isNew(), is(true));
@@ -197,7 +198,7 @@ public class ViolationTrackingDecoratorTest {
referenceViolation.setCreatedAt(referenceDate);
assertThat(newViolation.getCreatedAt(), nullValue());
- Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Lists.<RuleFailureModel>newArrayList(referenceViolation));
+ Map<Violation, RuleFailureModel> mapping = decorator.mapViolations(Lists.newArrayList(newViolation), Lists.<RuleFailureModel> newArrayList(referenceViolation));
assertThat(mapping.size(), is(1));
assertThat(newViolation.getCreatedAt(), is(referenceDate));
assertThat(newViolation.isNew(), is(false));
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
index 2708f843d17..9b734290990 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
@@ -19,13 +19,17 @@
*/
package org.sonar.plugins.cpd;
-import org.sonar.api.*;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.BatchExtension;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
import org.sonar.api.PropertyType;
+import org.sonar.api.SonarPlugin;
import org.sonar.plugins.cpd.decorators.DuplicationDensityDecorator;
import org.sonar.plugins.cpd.decorators.SumDuplicationsDecorator;
import org.sonar.plugins.cpd.index.IndexFactory;
-import java.util.Arrays;
import java.util.List;
@Properties({
@@ -92,12 +96,15 @@ import java.util.List;
})
public final class CpdPlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(CpdSensor.class, SumDuplicationsDecorator.class, DuplicationDensityDecorator.class,
- IndexFactory.class,
- SonarEngine.class,
- PmdEngine.class,
- SonarBridgeEngine.class);
+ public List<Class<? extends BatchExtension>> getExtensions() {
+ return ImmutableList.of(
+ CpdSensor.class,
+ SumDuplicationsDecorator.class,
+ DuplicationDensityDecorator.class,
+ IndexFactory.class,
+ SonarEngine.class,
+ PmdEngine.class,
+ SonarBridgeEngine.class);
}
}
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java
index 54a86f56063..3bbedf7f787 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java
@@ -56,8 +56,7 @@ public class PmdEngineTest {
public void defaultMinimumTokens() {
Project project = createJavaProject().setConfiguration(new PropertiesConfiguration());
- PmdEngine engine = new PmdEngine();
- assertEquals(CoreProperties.CPD_MINIMUM_TOKENS_DEFAULT_VALUE, engine.getMinimumTokens(project));
+ assertEquals(CoreProperties.CPD_MINIMUM_TOKENS_DEFAULT_VALUE, PmdEngine.getMinimumTokens(project));
}
@Test
@@ -66,8 +65,7 @@ public class PmdEngineTest {
conf.setProperty("sonar.cpd.minimumTokens", "33");
Project project = createJavaProject().setConfiguration(conf);
- PmdEngine engine = new PmdEngine();
- assertEquals(33, engine.getMinimumTokens(project));
+ assertEquals(33, PmdEngine.getMinimumTokens(project));
}
@Test
@@ -79,9 +77,8 @@ public class PmdEngineTest {
Project phpProject = createPhpProject().setConfiguration(conf);
Project javaProject = createJavaProject().setConfiguration(conf);
- PmdEngine engine = new PmdEngine();
- assertEquals(100, engine.getMinimumTokens(javaProject));
- assertEquals(33, engine.getMinimumTokens(phpProject));
+ assertEquals(100, PmdEngine.getMinimumTokens(javaProject));
+ assertEquals(33, PmdEngine.getMinimumTokens(phpProject));
}
private Project createJavaProject() {
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
index 4507771468f..6b2921e61a4 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
@@ -19,6 +19,8 @@
*/
package org.sonar.plugins.dbcleaner;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.BatchExtension;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.PropertyType;
@@ -26,7 +28,6 @@ import org.sonar.api.SonarPlugin;
import org.sonar.plugins.dbcleaner.api.DbCleanerConstants;
import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner;
-import java.util.Arrays;
import java.util.List;
@Properties({
@@ -50,11 +51,13 @@ import java.util.List;
global = true,
project = true,
type = PropertyType.INTEGER)
-}
-)
+})
public final class DbCleanerPlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(DefaultPeriodCleaner.class, DefaultPurgeTask.class, ProjectPurgePostJob.class);
+ public List<Class<? extends BatchExtension>> getExtensions() {
+ return ImmutableList.of(
+ DefaultPeriodCleaner.class,
+ DefaultPurgeTask.class,
+ ProjectPurgePostJob.class);
}
}
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
index 9711b383533..3f7f7881077 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
@@ -24,9 +24,6 @@ import org.hamcrest.Description;
import org.sonar.api.utils.DateUtils;
import org.sonar.core.purge.PurgeableSnapshotDto;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
public final class DbCleanerTestUtils {
private DbCleanerTestUtils() {
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java
index 17317064d31..bea6ed413b6 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java
+++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java
@@ -19,30 +19,24 @@
*/
package org.sonar.plugins.dbcleaner.api;
+import com.google.common.collect.Lists;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.junit.Test;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Scopes;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import com.google.common.collect.Lists;
+import javax.persistence.Query;
-import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
-import javax.persistence.Query;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PurgeUtilsTest extends AbstractDbUnitTestCase {
@@ -59,7 +53,7 @@ public class PurgeUtilsTest extends AbstractDbUnitTestCase {
}
@Test
- public void purgeSnapshots() throws SQLException {
+ public void purgeSnapshots() {
setupData("purgeSnapshots");
PurgeUtils.deleteSnapshotsData(getSession(), Arrays.asList(3, 4));
@@ -75,7 +69,7 @@ public class PurgeUtilsTest extends AbstractDbUnitTestCase {
when(session.createNativeQuery(anyString())).thenReturn(query);
List<Integer> ids = Lists.newArrayList();
- for (int i = 0; i < PurgeUtils.MAX_IN_ELEMENTS + 1; i++) {
+ for (int i = 0; i < (PurgeUtils.MAX_IN_ELEMENTS + 1); i++) {
ids.add(i);
}
diff --git a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
index cb643053bfa..50805055b42 100644
--- a/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
+++ b/plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
@@ -19,8 +19,8 @@
*/
package org.sonar.plugins.design;
-import java.util.List;
-
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.Extension;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.design.batch.FileTangleIndexDecorator;
import org.sonar.plugins.design.batch.MavenDependenciesSensor;
@@ -34,29 +34,25 @@ import org.sonar.plugins.design.ui.widgets.ChidamberKemererWidget;
import org.sonar.plugins.design.ui.widgets.FileDesignWidget;
import org.sonar.plugins.design.ui.widgets.PackageDesignWidget;
-import com.google.common.collect.Lists;
+import java.util.List;
public class DesignPlugin extends SonarPlugin {
- @SuppressWarnings({"unchecked", "rawtypes"})
- public List getExtensions() {
- List extensions = Lists.newArrayList();
-
- // Batch
- extensions.add(MavenDependenciesSensor.class);
- extensions.add(ProjectDsmDecorator.class);
- extensions.add(PackageTangleIndexDecorator.class);
- extensions.add(FileTangleIndexDecorator.class);
- extensions.add(SuspectLcom4DensityDecorator.class);
- extensions.add(GwtLibrariesPage.class);
-
- // UI
- extensions.add(GwtDesignPage.class);
- extensions.add(DependenciesViewer.class);
- extensions.add(FileDesignWidget.class);
- extensions.add(PackageDesignWidget.class);
- extensions.add(ChidamberKemererWidget.class);
-
- return extensions;
+ public List<Class<? extends Extension>> getExtensions() {
+ return ImmutableList.of(
+ // Batch
+ MavenDependenciesSensor.class,
+ ProjectDsmDecorator.class,
+ PackageTangleIndexDecorator.class,
+ FileTangleIndexDecorator.class,
+ SuspectLcom4DensityDecorator.class,
+ GwtLibrariesPage.class,
+
+ // UI
+ GwtDesignPage.class,
+ DependenciesViewer.class,
+ FileDesignWidget.class,
+ PackageDesignWidget.class,
+ ChidamberKemererWidget.class);
}
}
diff --git a/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java b/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java
index a0a3b8a28fd..da8a1180289 100644
--- a/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java
+++ b/plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java
@@ -35,7 +35,7 @@ import static org.junit.Assert.assertThat;
public class DsmSerializerTest {
@Test
- public void serializeEmptyDsm() throws IOException {
+ public void serializeEmptyDsm() {
Dsm dsm = new Dsm(new DirectedGraph());
assertThat(DsmSerializer.serialize(dsm), is("[]"));
}
@@ -51,7 +51,6 @@ public class DsmSerializerTest {
graph.addVertex(bar);
graph.addEdge(dep);
-
Dsm<Resource> dsm = new Dsm<Resource>(graph);
DsmManualSorter.sort(dsm, bar, foo); // for test reproductibility
String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/plugins/design/batch/DsmSerializerTest/dsm.json"));
diff --git a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
index 9c8965c2366..49e7befdf79 100644
--- a/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
+++ b/plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
@@ -19,20 +19,20 @@
*/
package org.sonar.plugins.emailnotifications;
-import java.util.Arrays;
-import java.util.List;
-
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.ServerExtension;
import org.sonar.api.SonarPlugin;
import org.sonar.plugins.emailnotifications.newviolations.NewViolationsEmailTemplate;
import org.sonar.plugins.emailnotifications.newviolations.NewViolationsOnMyFavouriteProject;
import org.sonar.plugins.emailnotifications.reviews.ChangesInReviewAssignedToMeOrCreatedByMe;
import org.sonar.plugins.emailnotifications.reviews.ReviewEmailTemplate;
+import java.util.List;
+
public class EmailNotificationsPlugin extends SonarPlugin {
- @SuppressWarnings({"rawtypes", "unchecked"})
- public List getExtensions() {
- return Arrays.asList(
+ public List<Class<? extends ServerExtension>> getExtensions() {
+ return ImmutableList.of(
EmailConfiguration.class,
EmailNotificationChannel.class,
diff --git a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java
index 070dfbee8bd..cb2da99ec37 100644
--- a/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java
+++ b/plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java
@@ -19,10 +19,14 @@
*/
package org.sonar.plugins.findbugs;
-import org.sonar.api.*;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Extension;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
import org.sonar.api.PropertyType;
+import org.sonar.api.SonarPlugin;
-import java.util.ArrayList;
import java.util.List;
@Properties({
@@ -53,15 +57,14 @@ import java.util.List;
public class FindbugsPlugin extends SonarPlugin {
public List<Class<? extends Extension>> getExtensions() {
- List<Class<? extends Extension>> list = new ArrayList<Class<? extends Extension>>();
- list.add(FindbugsSensor.class);
- list.add(FindbugsConfiguration.class);
- list.add(FindbugsExecutor.class);
- list.add(FindbugsRuleRepository.class);
- list.add(FindbugsProfileExporter.class);
- list.add(FindbugsProfileImporter.class);
- list.add(SonarWayWithFindbugsProfile.class);
- list.add(FindbugsMavenInitializer.class);
- return list;
+ return ImmutableList.of(
+ FindbugsSensor.class,
+ FindbugsConfiguration.class,
+ FindbugsExecutor.class,
+ FindbugsRuleRepository.class,
+ FindbugsProfileExporter.class,
+ FindbugsProfileImporter.class,
+ SonarWayWithFindbugsProfile.class,
+ FindbugsMavenInitializer.class);
}
}
diff --git a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
index 90f9f121a9c..84d233f1e16 100644
--- a/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
+++ b/plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
@@ -41,10 +41,10 @@ import static org.junit.Assert.assertThat;
public class FindbugsProfileImporterTest {
- private FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder());
+ private final FindbugsProfileImporter importer = new FindbugsProfileImporter(new FakeRuleFinder());
@Test
- public void shouldImportPatterns() throws IOException {
+ public void shouldImportPatterns() {
String findbugsConf = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/shouldImportPatterns.xml");
RulesProfile profile = importer.importProfile(new StringReader(findbugsConf), ValidationMessages.create());
@@ -54,7 +54,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void shouldImportCodes() throws IOException {
+ public void shouldImportCodes() {
InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/findbugs/shouldImportCodes.xml");
RulesProfile profile = importer.importProfile(new InputStreamReader(input), ValidationMessages.create());
List<ActiveRule> results = profile.getActiveRules();
@@ -65,7 +65,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void shouldImportCategories() throws IOException {
+ public void shouldImportCategories() {
InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/findbugs/shouldImportCategories.xml");
RulesProfile profile = importer.importProfile(new InputStreamReader(input), ValidationMessages.create());
List<ActiveRule> results = profile.getActiveRules();
@@ -75,7 +75,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void shouldImportConfigurationBugInclude() throws IOException {
+ public void shouldImportConfigurationBugInclude() {
InputStream input = getClass().getResourceAsStream("/org/sonar/plugins/findbugs/findbugs-include.xml");
RulesProfile profile = importer.importProfile(new InputStreamReader(input), ValidationMessages.create());
List<ActiveRule> results = profile.getActiveRules();
@@ -98,7 +98,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void testImportingUncorrectXmlFile() throws IOException {
+ public void testImportingUncorrectXmlFile() {
String uncorrectFindbugsXml = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/uncorrectFindbugsXml.xml");
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = importer.importProfile(new StringReader(uncorrectFindbugsXml), messages);
@@ -109,7 +109,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void testImportingXmlFileWithUnknownRule() throws IOException {
+ public void testImportingXmlFileWithUnknownRule() {
String uncorrectFindbugsXml = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/findbugsXmlWithUnknownRule.xml");
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = importer.importProfile(new StringReader(uncorrectFindbugsXml), messages);
@@ -120,7 +120,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void testImportingXmlFileWithUnknownCategory() throws IOException {
+ public void testImportingXmlFileWithUnknownCategory() {
String uncorrectFindbugsXml = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/findbugsXmlWithUnknownCategory.xml");
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = importer.importProfile(new StringReader(uncorrectFindbugsXml), messages);
@@ -131,7 +131,7 @@ public class FindbugsProfileImporterTest {
}
@Test
- public void testImportingXmlFileWithUnknownCode() throws IOException {
+ public void testImportingXmlFileWithUnknownCode() {
String uncorrectFindbugsXml = TestUtils.getResourceContent("/org/sonar/plugins/findbugs/findbugsXmlWithUnknownCode.xml");
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = importer.importProfile(new StringReader(uncorrectFindbugsXml), messages);
diff --git a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java
index fae29ce55ef..8fd1e6c5cbd 100644
--- a/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java
+++ b/plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java
@@ -19,15 +19,16 @@
*/
package org.sonar.plugins.jacoco;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.BatchExtension;
import org.sonar.api.SonarPlugin;
-import java.util.Arrays;
import java.util.List;
public class JaCoCoPlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(
+ public List<Class<? extends BatchExtension>> getExtensions() {
+ return ImmutableList.of(
JacocoConfiguration.class,
JaCoCoAgentDownloader.class,
// Ant
diff --git a/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java b/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java
index c9040a80feb..19e8bb2262e 100644
--- a/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java
+++ b/plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java
@@ -19,6 +19,8 @@
*/
package org.sonar.plugins.l10n;
+import org.sonar.api.Extension;
+
import org.sonar.api.SonarPlugin;
import java.util.Collections;
@@ -26,7 +28,7 @@ import java.util.List;
public final class EnglishPackPlugin extends SonarPlugin {
- public List getExtensions() {
+ public List<Class<? extends Extension>> getExtensions() {
return Collections.emptyList();
}
}
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
index 1dbc6a4901e..0f485f897ef 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
@@ -19,7 +19,13 @@
*/
package org.sonar.plugins.pmd;
-import net.sourceforge.pmd.*;
+import net.sourceforge.pmd.PMD;
+import net.sourceforge.pmd.PMDException;
+import net.sourceforge.pmd.Report;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.RuleSetFactory;
+import net.sourceforge.pmd.RuleSets;
+import net.sourceforge.pmd.SourceType;
import net.sourceforge.pmd.renderers.Renderer;
import net.sourceforge.pmd.renderers.XMLRenderer;
import org.apache.commons.io.FileUtils;
@@ -34,22 +40,30 @@ import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.java.api.JavaUtils;
-import java.io.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
import java.util.List;
public class PmdExecutor implements BatchExtension {
private static final Logger LOG = LoggerFactory.getLogger(PmdExecutor.class);
- private PmdConfiguration configuration;
- private Project project;
+ private final PmdConfiguration configuration;
+ private final Project project;
public PmdExecutor(Project project, PmdConfiguration configuration) {
this.project = project;
this.configuration = configuration;
}
- public Report execute() throws IOException, PMDException {
+ public Report execute() throws IOException {
TimeProfiler profiler = new TimeProfiler().start("Execute PMD " + PmdVersion.getVersion());
ClassLoader initialClassLoader = Thread.currentThread().getContextClassLoader();
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java
index abf8dda0442..dff7b9f85bc 100644
--- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java
+++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java
@@ -19,15 +19,16 @@
*/
package org.sonar.plugins.pmd;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.Extension;
import org.sonar.api.SonarPlugin;
-import java.util.Arrays;
import java.util.List;
public class PmdPlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(
+ public List<Class<? extends Extension>> getExtensions() {
+ return ImmutableList.of(
PmdSensor.class,
PmdConfiguration.class,
PmdExecutor.class,
@@ -38,6 +39,6 @@ public class PmdPlugin extends SonarPlugin {
SonarWayWithFindbugsProfile.class,
SunConventionsProfile.class,
JavaCpdMapping.class
- );
+ );
}
}
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
index dd9feab2cd9..a45a7426075 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
@@ -19,7 +19,7 @@
*/
package org.sonar.plugins.pmd;
-import net.sourceforge.pmd.PMDException;
+import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
@@ -31,8 +31,6 @@ import org.sonar.api.resources.ProjectFileSystem;
import java.io.File;
import java.io.IOException;
-import java.net.URISyntaxException;
-import java.nio.charset.Charset;
import java.util.Arrays;
import static org.hamcrest.Matchers.nullValue;
@@ -48,14 +46,14 @@ public class PmdExecutorTest {
public TemporaryFolder temp = new TemporaryFolder();
@Test
- public void executeOnManySourceDirs() throws URISyntaxException, IOException, PMDException {
- final File workDir = temp.getRoot();
+ public void executeOnManySourceDirs() throws IOException {
+ File workDir = temp.getRoot();
Project project = new Project("two-source-dirs");
ProjectFileSystem fs = mock(ProjectFileSystem.class);
File root = new File(getClass().getResource("/org/sonar/plugins/pmd/PmdExecutorTest/executeOnManySourceDirs/").toURI());
when(fs.getSourceFiles(Java.INSTANCE)).thenReturn(Arrays.asList(new File(root, "src1/FirstClass.java"), new File(root, "src2/SecondClass.java")));
- when(fs.getSourceCharset()).thenReturn(Charset.forName("UTF-8"));
+ when(fs.getSourceCharset()).thenReturn(Charsets.UTF_8);
when(fs.getSonarWorkingDirectory()).thenReturn(workDir);
project.setFileSystem(fs);
@@ -77,13 +75,13 @@ public class PmdExecutorTest {
}
@Test
- public void ignorePmdFailures() throws URISyntaxException, IOException, PMDException {
+ public void ignorePmdFailures() throws IOException {
final File workDir = temp.getRoot();
Project project = new Project("ignorePmdFailures");
ProjectFileSystem fs = mock(ProjectFileSystem.class);
when(fs.getSourceFiles(Java.INSTANCE)).thenReturn(Arrays.asList(new File("test-resources/ignorePmdFailures/DoesNotCompile.java")));
- when(fs.getSourceCharset()).thenReturn(Charset.forName("UTF-8"));
+ when(fs.getSourceCharset()).thenReturn(Charsets.UTF_8);
when(fs.getSonarWorkingDirectory()).thenReturn(workDir);
project.setFileSystem(fs);
diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
index fcbbc68033d..7dac4cc592e 100644
--- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
+++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
@@ -19,11 +19,6 @@
*/
package org.sonar.plugins.pmd;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.CharSequenceReader;
import org.apache.commons.lang.StringUtils;
@@ -32,27 +27,34 @@ import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.rules.*;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.RuleQuery;
+import org.sonar.api.rules.XMLRuleParser;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.plugins.pmd.xml.PmdProperty;
import org.sonar.plugins.pmd.xml.PmdRule;
import org.sonar.test.TestUtils;
-import org.xml.sax.SAXException;
-import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.Collection;
import java.util.List;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
public class PmdProfileExporterTest {
- private PmdProfileExporter exporter = new PmdProfileExporter();
+ private final PmdProfileExporter exporter = new PmdProfileExporter();
@Test
- public void testExportProfile() throws IOException, SAXException {
+ public void testExportProfile() {
ServerFileSystem fileSystem = mock(ServerFileSystem.class);
PmdRuleRepository repository = new PmdRuleRepository(fileSystem, new XMLRuleParser());
List<Rule> rules = repository.createRules();
@@ -84,7 +86,7 @@ public class PmdProfileExporterTest {
}
private static class IsEqualIgnoringEOL extends TypeSafeMatcher<CharSequence> {
- private String expected;
+ private final String expected;
public IsEqualIgnoringEOL(CharSequence expected) {
this.expected = normalize(expected);
@@ -148,7 +150,7 @@ public class PmdProfileExporterTest {
private static class FakeRuleFinder implements RuleFinder {
- private List<Rule> rules;
+ private final List<Rule> rules;
public FakeRuleFinder(List<Rule> rules) {
this.rules = rules;
diff --git a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java
index 789c0c0d1cf..e67b02d531e 100644
--- a/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java
+++ b/plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java
@@ -19,10 +19,19 @@
*/
package org.sonar.plugins.squid;
-import org.sonar.api.*;
-import org.sonar.plugins.squid.decorators.*;
+import com.google.common.collect.ImmutableList;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.Extension;
+import org.sonar.api.Properties;
+import org.sonar.api.Property;
+import org.sonar.api.PropertyType;
+import org.sonar.api.SonarPlugin;
+import org.sonar.plugins.squid.decorators.ChidamberKemererDistributionBuilder;
+import org.sonar.plugins.squid.decorators.ClassesDecorator;
+import org.sonar.plugins.squid.decorators.FileComplexityDistributionDecorator;
+import org.sonar.plugins.squid.decorators.FunctionComplexityDistributionBuilder;
+import org.sonar.plugins.squid.decorators.FunctionsDecorator;
-import java.util.Arrays;
import java.util.List;
@Properties({
@@ -56,8 +65,8 @@ import java.util.List;
})
public final class SquidPlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(
+ public List<Class<? extends Extension>> getExtensions() {
+ return ImmutableList.of(
SquidSensor.class,
SquidRuleRepository.class,
JavaSourceImporter.class,
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
index 9022282aeba..4acbe703fe6 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
@@ -19,14 +19,7 @@
*/
package org.sonar.java.ast;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.Charset;
-
-import org.apache.commons.lang.CharEncoding;
+import com.google.common.base.Charsets;
import org.junit.Before;
import org.junit.Test;
import org.sonar.java.squid.JavaSquidConfiguration;
@@ -35,12 +28,18 @@ import org.sonar.squid.api.AnalysisException;
import org.sonar.squid.api.SourceProject;
import org.sonar.squid.measures.Metric;
+import java.nio.charset.Charset;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
public class JavaAstScannerTest {
private Squid squid;
@Before
- public void setup() throws UnsupportedEncodingException {
+ public void setup() {
squid = new Squid(new JavaSquidConfiguration(false, Charset.defaultCharset(), 0.9));
}
@@ -96,8 +95,8 @@ public class JavaAstScannerTest {
assertEquals(1, prj.getInt(Metric.FILES));
assertEquals(1, prj.getInt(Metric.COMMENT_LINES));
- assertNotNull(squid.search("ClassWithOnlyComment.java"));//file
- assertNull(squid.search("ClassWithOnlyComment"));//class
+ assertNotNull(squid.search("ClassWithOnlyComment.java"));// file
+ assertNull(squid.search("ClassWithOnlyComment"));// class
}
@Test
@@ -125,7 +124,7 @@ public class JavaAstScannerTest {
try {
System.setProperty("file.encoding", "UTF-16");
Charset defaultEncoding = Charset.defaultCharset();
- if ( !defaultEncoding.displayName().equals("UTF-16")) {
+ if (!defaultEncoding.displayName().equals("UTF-16")) {
return;
}
System.setProperty("file.encoding", "MacRoman");
@@ -153,7 +152,7 @@ public class JavaAstScannerTest {
@Test
public void testUTF8Encoding() {
- squid = new Squid(new JavaSquidConfiguration(false, Charset.forName(CharEncoding.UTF_8)));
+ squid = new Squid(new JavaSquidConfiguration(false, Charsets.UTF_8));
squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/special_cases/encoding/Utf8Encoding.java"));
SourceProject prj = squid.aggregate();
assertEquals(4, prj.getInt(Metric.METHODS));
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
index 08f7e4086f5..3ae79a74757 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
@@ -22,8 +22,6 @@ package org.sonar.java.ast.visitor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
index cf02869229d..f6c156a508d 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
@@ -20,7 +20,6 @@
package org.sonar.java.ast.visitor;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.sonar.java.ast.JavaAstScanner;
import org.sonar.java.ast.SquidTestUtils;
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
index 0cd45d4e473..ecc445843b0 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
@@ -19,17 +19,6 @@
*/
package org.sonar.plugins.squid;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.charset.Charset;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -40,6 +29,16 @@ import org.sonar.api.resources.InputFile;
import org.sonar.api.resources.JavaFile;
import org.sonar.api.utils.SonarException;
+import java.io.File;
+import java.nio.charset.Charset;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class JavaSourceImporterTest {
@Rule
@@ -61,7 +60,7 @@ public class JavaSourceImporterTest {
}
@Test
- public void shouldSetSource() throws IOException {
+ public void shouldSetSource() {
JavaFile javaFile = JavaFile.fromRelativePath("UndocumentedApi.java", true);
when(context.isIndexed(javaFile, true)).thenReturn(true);
importer.importSource(context, javaFile, inputFile, Charset.defaultCharset());
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
index 2bbbf210a66..0430ebf4c53 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
@@ -19,18 +19,6 @@
*/
package org.sonar.plugins.squid;
-import static org.hamcrest.core.Is.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyDouble;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-
import org.junit.Test;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.checks.AnnotationCheckFactory;
@@ -39,7 +27,6 @@ import org.sonar.api.profiles.RulesProfile;
import org.sonar.api.resources.InputFile;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
-import org.sonar.squid.Squid;
import org.sonar.squid.measures.Metric;
import java.io.File;
@@ -49,6 +36,18 @@ import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyDouble;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+
public class SquidExecutorTest {
@Test
@@ -61,7 +60,7 @@ public class SquidExecutorTest {
}
@Test
- public void doNotScanBytecodeIfNoSources() throws IOException, URISyntaxException {
+ public void doNotScanBytecodeIfNoSources() throws URISyntaxException {
SquidExecutor executor = new SquidExecutor(true, "LOG, logger", createCheckFactory(), Charset.defaultCharset());
executor.scan(Collections.<InputFile> emptyList(), Arrays.asList(SquidTestUtils.getStrutsCoreJar()));
@@ -106,7 +105,7 @@ public class SquidExecutorTest {
@Test
public void shouldNotHaveBytecode() {
- assertFalse(SquidExecutor.hasBytecode(Collections.<File>emptyList()));
+ assertFalse(SquidExecutor.hasBytecode(Collections.<File> emptyList()));
assertFalse(SquidExecutor.hasBytecode(Arrays.asList(new File("unknown"))));
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
index a2c6072c4a3..06279dd4d83 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
@@ -39,11 +39,11 @@ public final class SquidTestUtils {
*/
public static Collection<InputFile> getStrutsCoreSources() throws IOException, URISyntaxException {
File sourceDir = new File("target/struts-core-1.3.9-sources");
- if (!sourceDir.exists() || sourceDir.list().length==0) {
+ if (!sourceDir.exists() || (sourceDir.list().length == 0)) {
FileUtils.forceMkdir(sourceDir);
ZipUtils.unzip(new File(SquidTestUtils.class.getResource("/struts-core-1.3.9-sources.jar").toURI()), sourceDir);
}
- Collection<File> javaFiles = FileUtils.listFiles(sourceDir, new String[]{"java"}, true);
+ Collection<File> javaFiles = FileUtils.listFiles(sourceDir, new String[] {"java"}, true);
return InputFileUtils.create(sourceDir, javaFiles);
}
@@ -51,7 +51,7 @@ public final class SquidTestUtils {
/**
* See http://svn.apache.org/repos/asf/struts/struts1/tags/STRUTS_1_3_9/core
*/
- public static File getStrutsCoreJar() throws IOException, URISyntaxException {
+ public static File getStrutsCoreJar() throws URISyntaxException {
return new File(SquidTestUtils.class.getResource("/struts-core-1.3.9.jar").toURI());
}
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java
index 0820183a79a..6c8957cb287 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java
@@ -19,10 +19,7 @@
*/
package org.sonar.plugins.squid.bridges;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
+import com.google.common.base.Charsets;
import org.junit.Before;
import org.junit.BeforeClass;
import org.mockito.invocation.InvocationOnMock;
@@ -38,10 +35,13 @@ import org.sonar.plugins.squid.SquidTestUtils;
import java.io.IOException;
import java.net.URISyntaxException;
-import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public abstract class BridgeTestCase {
protected SensorContext context;
@@ -52,7 +52,7 @@ public abstract class BridgeTestCase {
public static void scanStruts() throws IOException, URISyntaxException {
RulesProfile profile = RulesProfile.create();
CheckFactory checkFactory = AnnotationCheckFactory.create(profile, "repo", Collections.<Class> emptyList());
- executor = new SquidExecutor(true, "LOG, logger", checkFactory, Charset.forName("UTF8"));
+ executor = new SquidExecutor(true, "LOG, logger", checkFactory, Charsets.UTF_8);
executor.scan(SquidTestUtils.getStrutsCoreSources(), Arrays.asList(SquidTestUtils.getStrutsCoreJar()));
project = new Project("project");
}
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
index 966ba8391a3..dd7fb7fc54f 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
@@ -31,7 +31,6 @@ import org.sonar.api.resources.JavaFile;
import org.sonar.api.resources.JavaPackage;
import org.sonar.squid.api.SourceFile;
import org.sonar.squid.measures.Metric;
-import org.sonar.squid.measures.MetricDef;
public class ChidamberKemererBridgeTest extends BridgeTestCase {
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java
index 9c1c1f8f2b1..f6d2d102b74 100644
--- a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java
+++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java
@@ -24,13 +24,13 @@ import org.junit.Test;
import org.sonar.api.design.Dependency;
import org.sonar.api.resources.JavaPackage;
import org.sonar.api.resources.Resource;
+import org.sonar.graph.DirectedGraph;
+import org.sonar.graph.Dsm;
+import org.sonar.graph.DsmManualSorter;
import org.sonar.squid.api.SourceCode;
import org.sonar.squid.api.SourceCodeEdge;
import org.sonar.squid.api.SourceCodeEdgeUsage;
import org.sonar.squid.api.SourcePackage;
-import org.sonar.graph.DirectedGraph;
-import org.sonar.graph.Dsm;
-import org.sonar.graph.DsmManualSorter;
import java.io.IOException;
@@ -40,7 +40,7 @@ import static org.junit.Assert.assertThat;
public class DsmSerializerTest {
@Test
- public void serializeEmptyDsm() throws IOException {
+ public void serializeEmptyDsm() {
Dsm dsm = new Dsm(new DirectedGraph());
assertThat(DsmSerializer.serialize(dsm, new DependencyIndex(), new ResourceIndex()), is("[]"));
}
@@ -76,7 +76,6 @@ public class DsmSerializerTest {
resourceIndex.put(foo, fooSonar);
resourceIndex.put(bar, barSonar);
-
Dsm<SourceCode> dsm = new Dsm<SourceCode>(graph);
DsmManualSorter.sort(dsm, bar, foo); // for test reproductibility
String json = IOUtils.toString(getClass().getResourceAsStream("/org/sonar/plugins/squid/bridges/DsmSerializerTest/dsm.json"));
diff --git a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java
index c076e954fb0..b4eb8cc5e5d 100644
--- a/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java
+++ b/plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java
@@ -19,26 +19,26 @@
*/
package org.sonar.plugins.surefire;
+import com.google.common.collect.ImmutableList;
import org.sonar.api.CoreProperties;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.SonarPlugin;
-import java.util.Arrays;
import java.util.List;
@Properties({
- @Property(
- key = CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY,
- name = "Report path",
- description = "Path (absolute or relative) to XML report files.",
- project = true,
- global = false)
+ @Property(
+ key = CoreProperties.SUREFIRE_REPORTS_PATH_PROPERTY,
+ name = "Report path",
+ description = "Path (absolute or relative) to XML report files.",
+ project = true,
+ global = false)
})
public final class SurefirePlugin extends SonarPlugin {
- public List getExtensions() {
- return Arrays.asList(SurefireSensor.class);
+ public List<Class<SurefireSensor>> getExtensions() {
+ return ImmutableList.of(SurefireSensor.class);
}
}
diff --git a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java
index 8cdbe6cf062..e99590d2712 100644
--- a/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java
+++ b/plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java
@@ -21,8 +21,6 @@ package org.sonar.plugins.surefire.data;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.resources.JavaFile;
import org.sonar.api.utils.StaxParser;
import org.sonar.test.TestUtils;
@@ -32,8 +30,6 @@ import java.io.File;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
public class SurefireStaxHandlerTest {
diff --git a/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java b/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
index 2bbbbd276e7..53cdc2aadba 100644
--- a/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
+++ b/sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
@@ -84,7 +84,7 @@ public class JettyEmbedder {
});
}
- private Server configureProgrammatically() throws URISyntaxException, IOException {
+ private Server configureProgrammatically() throws URISyntaxException {
configureServer();
WebAppContext context = new WebAppContext(getPath("/war/sonar-server"), contextPath);
server.addHandler(context);
@@ -102,7 +102,7 @@ public class JettyEmbedder {
server.addHandler(requestLogHandler);
}
- private void configureServer() throws URISyntaxException {
+ private void configureServer() {
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMinThreads(5);
threadPool.setMaxThreads(50);
@@ -128,7 +128,7 @@ public class JettyEmbedder {
List<String> paths = new ArrayList<String>();
paths.add(pluginsDir.getCanonicalPath() + System.getProperty("file.separator"));
- Collection<File> files = FileUtils.listFiles(pluginsDir, new String[]{"jar"}, false);
+ Collection<File> files = FileUtils.listFiles(pluginsDir, new String[] {"jar"}, false);
if (files != null) {
for (File file : files) {
paths.add(file.getCanonicalPath());
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");
}
}
diff --git a/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java b/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java
index 3bf47118a8d..0370e8e1ded 100644
--- a/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java
+++ b/sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java
@@ -19,14 +19,6 @@
*/
package org.sonar.check;
-import org.junit.Test;
-
-import java.lang.reflect.Field;
-import java.util.List;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
-
@Check(isoCategory = IsoCategory.Portability, priority = Priority.CRITICAL)
class SimplestCheck {
diff --git a/sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java b/sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java
index 61d57c7daab..5808a02afee 100644
--- a/sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java
+++ b/sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java
@@ -60,7 +60,7 @@ public class UserGuideTest {
}
@Test
- public void defineNewLanguage() throws IOException {
+ public void defineNewLanguage() {
}
diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
index 0c2b1b75415..b0e7dec94fd 100644
--- a/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
+++ b/sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
@@ -24,12 +24,23 @@ import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.builder.xml.XMLMapperBuilder;
import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.mapping.Environment;
-import org.apache.ibatis.session.*;
+import org.apache.ibatis.session.Configuration;
+import org.apache.ibatis.session.ExecutorType;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
-import org.sonar.core.dashboard.*;
+import org.sonar.core.dashboard.ActiveDashboardDto;
+import org.sonar.core.dashboard.ActiveDashboardMapper;
+import org.sonar.core.dashboard.DashboardDto;
+import org.sonar.core.dashboard.DashboardMapper;
+import org.sonar.core.dashboard.WidgetDto;
+import org.sonar.core.dashboard.WidgetMapper;
+import org.sonar.core.dashboard.WidgetPropertyDto;
+import org.sonar.core.dashboard.WidgetPropertyMapper;
import org.sonar.core.duplication.DuplicationMapper;
import org.sonar.core.duplication.DuplicationUnitDto;
import org.sonar.core.properties.PropertiesMapper;
@@ -37,7 +48,11 @@ import org.sonar.core.properties.PropertyDto;
import org.sonar.core.purge.PurgeMapper;
import org.sonar.core.purge.PurgeVendorMapper;
import org.sonar.core.purge.PurgeableSnapshotDto;
-import org.sonar.core.resource.*;
+import org.sonar.core.resource.ResourceDto;
+import org.sonar.core.resource.ResourceIndexDto;
+import org.sonar.core.resource.ResourceIndexerMapper;
+import org.sonar.core.resource.ResourceMapper;
+import org.sonar.core.resource.SnapshotDto;
import org.sonar.core.review.ReviewDto;
import org.sonar.core.review.ReviewMapper;
import org.sonar.core.rule.RuleDto;
@@ -47,19 +62,18 @@ import org.sonar.core.template.LoadedTemplateMapper;
import org.sonar.core.user.AuthorDto;
import org.sonar.core.user.AuthorMapper;
-import java.io.IOException;
import java.io.InputStream;
public class MyBatis implements BatchComponent, ServerComponent {
- private Database database;
+ private final Database database;
private SqlSessionFactory sessionFactory;
public MyBatis(Database database) {
this.database = database;
}
- public MyBatis start() throws IOException {
+ public MyBatis start() {
LogFactory.useSlf4jLogging();
Configuration conf = new Configuration();
conf.setEnvironment(new Environment("production", createTransactionFactory(), database.getDataSource()));
@@ -128,7 +142,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
}
}
- private void loadMapper(Configuration conf, Class mapperClass) throws IOException {
+ private void loadMapper(Configuration conf, Class mapperClass) {
// trick to use database-specific XML files for a single Mapper Java interface
InputStream input = getPathToMapper(mapperClass);
try {
@@ -143,7 +157,7 @@ public class MyBatis implements BatchComponent, ServerComponent {
private InputStream getPathToMapper(Class mapperClass) {
InputStream input = getClass().getResourceAsStream(
- "/" + StringUtils.replace(mapperClass.getName(), ".", "/") + "-" + database.getDialect().getId() + ".xml");
+ "/" + StringUtils.replace(mapperClass.getName(), ".", "/") + "-" + database.getDialect().getId() + ".xml");
if (input == null) {
input = getClass().getResourceAsStream("/" + StringUtils.replace(mapperClass.getName(), ".", "/") + ".xml");
}
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java
index 0fc45efaac0..048c5d3df49 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java
@@ -26,7 +26,6 @@ import org.sonar.api.config.Settings;
import org.sonar.core.persistence.dialect.Oracle;
import org.sonar.core.persistence.dialect.PostgreSql;
-import java.sql.SQLException;
import java.util.Properties;
import static org.hamcrest.Matchers.nullValue;
@@ -38,7 +37,6 @@ public class DefaultDatabaseTest {
DerbyUtils.fixDerbyLogs();
}
-
@Test
public void shouldLoadDefaultValues() {
DefaultDatabase db = new DefaultDatabase(new Settings());
@@ -97,7 +95,7 @@ public class DefaultDatabaseTest {
}
@Test
- public void shouldStart() throws SQLException {
+ public void shouldStart() {
Settings settings = new Settings();
settings.setProperty("sonar.jdbc.url", "jdbc:derby:memory:sonar;create=true;user=sonar;password=sonar");
settings.setProperty("sonar.jdbc.driverClassName", "org.apache.derby.jdbc.EmbeddedDriver");
@@ -116,7 +114,6 @@ public class DefaultDatabaseTest {
}
}
-
@Test
public void shouldInitSchema() {
Settings settings = new Settings();
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java
index 23d7bc30be1..3e6bb1b6fa6 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java
@@ -47,12 +47,11 @@ public class InMemoryDatabaseTest {
Connection connection = db.getDataSource().getConnection();
assertNotNull(connection);
- ResultSet resultSet = connection.getMetaData().getTables("", null, null, new String[]{"TABLE"});
+ ResultSet resultSet = connection.getMetaData().getTables("", null, null, new String[] {"TABLE"});
while (resultSet.next()) {
tables++;
}
-
} finally {
db.stop();
}
@@ -60,12 +59,12 @@ public class InMemoryDatabaseTest {
}
@Test
- public void shouldLimitThePoolSize() throws SQLException {
+ public void shouldLimitThePoolSize() {
InMemoryDatabase db = new InMemoryDatabase();
try {
db.startDatabase();
- assertThat(((BasicDataSource)db.getDataSource()).getMaxActive(), Is.is(2));
- assertThat(((BasicDataSource)db.getDataSource()).getMaxIdle(), Is.is(2));
+ assertThat(((BasicDataSource) db.getDataSource()).getMaxActive(), Is.is(2));
+ assertThat(((BasicDataSource) db.getDataSource()).getMaxIdle(), Is.is(2));
} finally {
db.stop();
diff --git a/sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java b/sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java
index 1905ded8649..592bca54484 100644
--- a/sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java
@@ -27,8 +27,6 @@ import org.junit.BeforeClass;
import org.junit.Test;
import org.sonar.core.rule.RuleMapper;
-import java.io.IOException;
-
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
@@ -42,19 +40,19 @@ public class MyBatisTest {
private static InMemoryDatabase database;
@BeforeClass
- public static void start() throws IOException {
+ public static void start() {
database = new InMemoryDatabase();
myBatis = new MyBatis(database.start());
myBatis.start();
}
@AfterClass
- public static void stop() throws IOException {
+ public static void stop() {
database.stop();
}
@Test
- public void shouldConfigureMyBatis() throws IOException {
+ public void shouldConfigureMyBatis() {
Configuration conf = myBatis.getSessionFactory().getConfiguration();
assertThat(conf.isUseGeneratedKeys(), Is.is(true));
assertThat(conf.hasMapper(RuleMapper.class), Is.is(true));
@@ -62,7 +60,7 @@ public class MyBatisTest {
}
@Test
- public void shouldOpenBatchSession() throws IOException {
+ public void shouldOpenBatchSession() {
SqlSession session = myBatis.openBatchSession();
try {
assertThat(session.getConnection(), notNullValue());
diff --git a/sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java b/sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java
index eac34fb50a9..404df716657 100644
--- a/sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java
+++ b/sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java
@@ -23,7 +23,6 @@ import org.junit.Test;
import java.io.File;
import java.io.FilenameFilter;
-import java.io.IOException;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
@@ -36,7 +35,7 @@ import static org.junit.Assert.assertThat;
public class AbstractLanguageTest {
@Test
- public void shouldCreateCorrectFilenameFilterForExtensions() throws IOException {
+ public void shouldCreateCorrectFilenameFilterForExtensions() {
AbstractLanguage language = new AbstractLanguage(null, "java") {
};
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
index 93a8a604b75..840ad390df0 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
@@ -19,14 +19,7 @@
*/
package org.sonar.duplications.java;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
-
-import java.io.*;
-import java.nio.charset.Charset;
-import java.util.List;
-
+import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.sonar.duplications.DuplicationsTestUtil;
@@ -34,10 +27,21 @@ import org.sonar.duplications.statement.Statement;
import org.sonar.duplications.statement.StatementChunker;
import org.sonar.duplications.token.TokenChunker;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.List;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+
public class JavaStatementBuilderTest {
- private TokenChunker tokenChunker = JavaTokenProducer.build();
- private StatementChunker statementChunker = JavaStatementBuilder.build();
+ private final TokenChunker tokenChunker = JavaTokenProducer.build();
+ private final StatementChunker statementChunker = JavaStatementBuilder.build();
private List<Statement> chunk(String sourceCode) {
return statementChunker.chunk(tokenChunker.chunk(sourceCode));
@@ -56,9 +60,9 @@ public class JavaStatementBuilderTest {
@Test
public void shouldHandleAnnotation() {
List<Statement> statements = chunk("" +
- "@Entity" +
- "@Table(name = \"properties\")" +
- "@Column(updatable = true, nullable = true)");
+ "@Entity" +
+ "@Table(name = \"properties\")" +
+ "@Column(updatable = true, nullable = true)");
assertThat(statements.size(), is(3));
assertThat(statements.get(0).getValue(), is("@Entity"));
assertThat(statements.get(1).getValue(), is("@Table(name=$CHARS)"));
@@ -124,11 +128,11 @@ public class JavaStatementBuilderTest {
@Test
public void shouldHandleSwitch() {
List<Statement> statements = chunk("" +
- "switch (month) {" +
- " case 1 : monthString=\"January\"; break;" +
- " case 2 : monthString=\"February\"; break;" +
- " default: monthString=\"Invalid\";" +
- "}");
+ "switch (month) {" +
+ " case 1 : monthString=\"January\"; break;" +
+ " case 2 : monthString=\"February\"; break;" +
+ " default: monthString=\"Invalid\";" +
+ "}");
assertThat(statements.size(), is(6));
assertThat(statements.get(0).getValue(), is("switch(month)"));
assertThat(statements.get(1).getValue(), is("case$NUMBER:monthString=$CHARS"));
@@ -144,10 +148,10 @@ public class JavaStatementBuilderTest {
@Test
public void shouldHandleNestedSwitch() {
List<Statement> statements = chunk("" +
- "switch (a) {" +
- " case 'a': case 'b': case 'c': something(); break;" +
- " case 'd': case 'e': case 'f': somethingOther(); break;" +
- "}");
+ "switch (a) {" +
+ " case 'a': case 'b': case 'c': something(); break;" +
+ " case 'd': case 'e': case 'f': somethingOther(); break;" +
+ "}");
assertThat(statements.size(), is(5));
assertThat(statements.get(0).getValue(), is("switch(a)"));
assertThat(statements.get(1).getValue(), is("case$CHARS:case$CHARS:case$CHARS:something()"));
@@ -325,7 +329,7 @@ public class JavaStatementBuilderTest {
private List<Statement> chunk(File file) {
Reader reader = null;
try {
- reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
+ reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
return statementChunker.chunk(tokenChunker.chunk(reader));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
index 9e225025d8a..86641ad98fd 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
@@ -19,32 +19,31 @@
*/
package org.sonar.duplications.java;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.number.OrderingComparisons.greaterThan;
-import static org.junit.Assert.assertThat;
+import com.google.common.base.Charsets;
+import com.google.common.collect.Lists;
+import org.apache.commons.io.IOUtils;
+import org.hamcrest.Matcher;
+import org.junit.Test;
+import org.sonar.duplications.DuplicationsTestUtil;
+import org.sonar.duplications.token.Token;
+import org.sonar.duplications.token.TokenChunker;
+import org.sonar.duplications.token.TokenQueue;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
-import org.apache.commons.io.IOUtils;
-import org.hamcrest.Matcher;
-import org.junit.Test;
-import org.sonar.duplications.DuplicationsTestUtil;
-import org.sonar.duplications.token.Token;
-import org.sonar.duplications.token.TokenChunker;
-import org.sonar.duplications.token.TokenQueue;
-
-import com.google.common.collect.Lists;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
public class JavaTokenProducerTest {
- private TokenChunker chunker = JavaTokenProducer.build();
+ private final TokenChunker chunker = JavaTokenProducer.build();
/**
* <a href="http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.6">White Space</a>
@@ -313,7 +312,7 @@ public class JavaTokenProducerTest {
private TokenQueue chunk(File file) {
Reader reader = null;
try {
- reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
+ reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8);
return chunker.chunk(reader);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
diff --git a/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java b/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
index 36166eb95cf..06818fc2856 100644
--- a/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
+++ b/sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
@@ -19,8 +19,6 @@
*/
package org.sonar.graph;
-import java.io.IOException;
-
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -55,7 +53,7 @@ public class DsmTopologicalSorterTest {
}
@Test(expected = IllegalStateException.class)
- public void sortCyclicGraph() throws IOException {
+ public void sortCyclicGraph() {
StringPrintWriter textDsm = new StringPrintWriter();
textDsm.println(" | A | B | C | D |");
textDsm.println("A | | | | |");
@@ -68,7 +66,7 @@ public class DsmTopologicalSorterTest {
}
@Test
- public void sortCyclicGraphWithManuallyFlaggedFeedbackEdges() throws IOException {
+ public void sortCyclicGraphWithManuallyFlaggedFeedbackEdges() {
StringPrintWriter textDsm = new StringPrintWriter();
textDsm.println(" | A | B | C | D |");
textDsm.println("A | | | | |");
@@ -90,7 +88,7 @@ public class DsmTopologicalSorterTest {
}
@Test
- public void sortCyclicGraphWithFlaggedFeedbackEdges() throws IOException {
+ public void sortCyclicGraphWithFlaggedFeedbackEdges() {
DirectedGraph<String, StringEdge> dcg = DirectedGraph.createStringDirectedGraph();
dcg.addEdge("A", "B", 3).addEdge("B", "A", 1);
CycleDetector<String> cycleDetector = new CycleDetector<String>(dcg);
diff --git a/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java b/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
index a00c4625a82..0702e945344 100644
--- a/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
+++ b/sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
@@ -21,7 +21,6 @@ package org.sonar.graph;
import org.junit.Test;
-import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
diff --git a/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java b/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
index cb89b059f41..34a146b2e76 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
@@ -23,7 +23,6 @@ import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;
-import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
import org.sonar.wsclient.gwt.GwtUtils;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
index 74e1bfe06a4..0904ac3a293 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
@@ -30,13 +30,11 @@ import javax.annotation.Nullable;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
+
import java.io.File;
import java.io.IOException;
-import java.security.InvalidKeyException;
import java.security.Key;
-import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
-import java.security.spec.InvalidKeySpecException;
final class AesCipher extends Cipher {
@@ -53,6 +51,7 @@ final class AesCipher extends Cipher {
this.settings = settings;
}
+ @Override
String encrypt(String clearText) {
try {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
@@ -63,6 +62,7 @@ final class AesCipher extends Cipher {
}
}
+ @Override
String decrypt(String encryptedText) {
try {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
@@ -86,13 +86,13 @@ final class AesCipher extends Cipher {
return false;
}
- private Key loadSecretFile() throws NoSuchAlgorithmException, InvalidKeySpecException, IOException, InvalidKeyException {
+ private Key loadSecretFile() throws IOException {
String path = getPathToSecretKey();
return loadSecretFileFromFile(path);
}
@VisibleForTesting
- Key loadSecretFileFromFile(@Nullable String path) throws NoSuchAlgorithmException, InvalidKeySpecException, IOException, InvalidKeyException {
+ Key loadSecretFileFromFile(@Nullable String path) throws IOException {
if (StringUtils.isBlank(path)) {
throw new IllegalStateException("Secret key not found. Please set the property " + CoreProperties.ENCRYPTION_SECRET_KEY_PATH);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java
index de4d4ec82a4..07dee384d61 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java
@@ -35,7 +35,7 @@ import java.util.Collection;
*/
public final class AnnotationProfileParser implements ServerComponent {
- private RuleFinder ruleFinder;
+ private final RuleFinder ruleFinder;
public AnnotationProfileParser(RuleFinder ruleFinder) {
this.ruleFinder = ruleFinder;
@@ -43,15 +43,15 @@ public final class AnnotationProfileParser implements ServerComponent {
public RulesProfile parse(String repositoryKey, String profileName, String language, Collection<Class> annotatedClasses, ValidationMessages messages) {
RulesProfile profile = RulesProfile.create(profileName, language);
- for (Class aClass : annotatedClasses) {
- BelongsToProfile belongsToProfile = (BelongsToProfile) aClass.getAnnotation(BelongsToProfile.class);
+ for (Class<?> aClass : annotatedClasses) {
+ BelongsToProfile belongsToProfile = aClass.getAnnotation(BelongsToProfile.class);
addRule(aClass, belongsToProfile, profile, repositoryKey, messages);
}
return profile;
}
private void addRule(Class aClass, BelongsToProfile annotation, RulesProfile profile, String repositoryKey, ValidationMessages messages) {
- if (annotation != null && StringUtils.equals(annotation.title(), profile.getName())) {
+ if ((annotation != null) && StringUtils.equals(annotation.title(), profile.getName())) {
String ruleKey = RuleAnnotationUtils.getRuleKey(aClass);
Rule rule = ruleFinder.findByKey(repositoryKey, ruleKey);
if (rule == null) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
index da1ffdf3b47..8c8f876c00b 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
@@ -19,10 +19,9 @@
*/
package org.sonar.api.profiles;
+import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.CharEncoding;
import org.apache.commons.lang.StringUtils;
-import org.codehaus.stax2.XMLInputFactory2;
import org.codehaus.staxmate.SMInputFactory;
import org.codehaus.staxmate.in.SMHierarchicCursor;
import org.codehaus.staxmate.in.SMInputCursor;
@@ -36,15 +35,14 @@ import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.Logs;
import org.sonar.api.utils.ValidationMessages;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
import java.io.InputStreamReader;
import java.io.Reader;
-import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamException;
-
/**
* TODO should be an interface
*
@@ -52,7 +50,7 @@ import javax.xml.stream.XMLStreamException;
*/
public final class XMLProfileParser implements ServerComponent {
- private RuleFinder ruleFinder;
+ private final RuleFinder ruleFinder;
private MetricFinder metricFinder;
/**
@@ -77,7 +75,7 @@ public final class XMLProfileParser implements ServerComponent {
}
public RulesProfile parseResource(ClassLoader classloader, String xmlClassPath, ValidationMessages messages) {
- Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charset.forName(CharEncoding.UTF_8));
+ Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charsets.UTF_8);
try {
return parse(reader, messages);
@@ -127,7 +125,7 @@ public final class XMLProfileParser implements ServerComponent {
}
private SMInputFactory initStax() {
- XMLInputFactory xmlFactory = XMLInputFactory2.newInstance();
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
xmlFactory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
xmlFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.FALSE);
// just so it won't try to load DTD in if there's DOCTYPE
@@ -172,7 +170,7 @@ public final class XMLProfileParser implements ServerComponent {
for (Map.Entry<String, String> entry : parameters.entrySet()) {
if (rule.getParam(entry.getKey()) == null) {
messages.addWarningText("The parameter '" + entry.getKey() + "' does not exist in the rule: [repository=" + repositoryKey
- + ", key=" + key + "]");
+ + ", key=" + key + "]");
} else {
activeRule.setParameter(entry.getKey(), entry.getValue());
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
index d2eacf3eb51..59bc02e8359 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
@@ -28,10 +28,14 @@ import org.hamcrest.Description;
import org.junit.Before;
import org.junit.Test;
import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.ProjectFileSystem;
+import org.sonar.api.resources.Resource;
import java.io.File;
-import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.Arrays;
@@ -41,8 +45,14 @@ import java.util.List;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class AbstractSourceImporterTest {
@@ -52,8 +62,8 @@ public class AbstractSourceImporterTest {
@Before
public void setup() throws UnsupportedEncodingException {
- aClaess = new String(new byte[] { 65, 67, 108, 97, -61, -88, 115, 115, 40, 41 }, CharEncoding.UTF_8);
- explicacao = new String(new byte[] { 101, 120, 112, 108, 105, 99, 97, -61, -89, -61, -93, 111, 40, 41 }, CharEncoding.UTF_8);
+ aClaess = new String(new byte[] {65, 67, 108, 97, -61, -88, 115, 115, 40, 41}, CharEncoding.UTF_8);
+ explicacao = new String(new byte[] {101, 120, 112, 108, 105, 99, 97, -61, -89, -61, -93, 111, 40, 41}, CharEncoding.UTF_8);
importer = new FakeSourceImporter();
}
@@ -65,7 +75,7 @@ public class AbstractSourceImporterTest {
}
@Test
- public void doNotSaveSourceIfNullResource() throws IOException {
+ public void doNotSaveSourceIfNullResource() {
AbstractSourceImporter nullImporter = new AbstractSourceImporter(Java.INSTANCE) {
@Override
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
index f7bce23c103..392df440a20 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
@@ -19,16 +19,18 @@
*/
package org.sonar.api.batch.maven;
+import com.google.common.base.Charsets;
import org.apache.maven.project.MavenProject;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.test.MavenTestUtils;
import java.nio.charset.Charset;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
public class MavenUtilsTest {
private MavenProject pom;
@@ -57,6 +59,6 @@ public class MavenUtilsTest {
@Test
public void testSourceEncoding() {
MavenProject pom = MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenPomWithSourceEncoding.xml");
- assertEquals(MavenUtils.getSourceCharset(pom), Charset.forName("UTF-16"));
+ assertEquals(MavenUtils.getSourceCharset(pom), Charsets.UTF_16);
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java
index b92dcfec2f9..3016077d07a 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java
@@ -23,16 +23,23 @@ import org.apache.commons.io.FileUtils;
import org.jfree.chart.ChartUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
-import static org.junit.Assert.assertTrue;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JPanel;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.image.BufferedImage;
-import java.io.*;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import static org.junit.Assert.assertTrue;
+
public abstract class AbstractChartTest {
protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -57,7 +64,7 @@ public abstract class AbstractChartTest {
}
- protected static void displayTestPanel(BufferedImage image) throws IOException {
+ protected static void displayTestPanel(BufferedImage image) {
ApplicationFrame frame = new ApplicationFrame("testframe");
BufferedPanel imgPanel = new BufferedPanel(image);
frame.setContentPane(imgPanel);
@@ -72,7 +79,7 @@ public abstract class AbstractChartTest {
}
private static class BufferedPanel extends JPanel {
- private BufferedImage chartImage;
+ private final BufferedImage chartImage;
public BufferedPanel(BufferedImage chartImage) {
this.chartImage = chartImage;
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
index 60670a372d3..895e37952e6 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
@@ -29,9 +29,13 @@ import org.sonar.api.utils.SonarException;
import java.util.Arrays;
-import static org.hamcrest.Matchers.*;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
public class AnnotationCheckFactoryTest {
@@ -42,7 +46,7 @@ public class AnnotationCheckFactoryTest {
public void createCheckWithoutProperties() {
RulesProfile profile = RulesProfile.create("repo", "java");
ActiveRule activeRule = profile.activateRule(Rule.create("repo", "org.sonar.api.checks.CheckWithoutProperties", ""), null);
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithoutProperties.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithoutProperties.class));
Object check = factory.getCheck(activeRule);
assertNotNull(check);
@@ -57,7 +61,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("pattern", "foo");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithStringProperty.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
Object check = factory.getCheck(activeRule);
assertNotNull(check);
@@ -75,7 +79,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("unknown", "bar");
- AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithStringProperty.class));
+ AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithStringProperty.class));
}
@Test
@@ -88,7 +92,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
activeRule.setParameter("ignore", "true");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithPrimitiveProperties.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithPrimitiveProperties.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithPrimitiveProperties) check).getMax(), is(300));
@@ -103,7 +107,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithIntegerProperty.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithIntegerProperty.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithIntegerProperty) check).getMax(), is(300));
@@ -120,7 +124,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(ImplementedCheck.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(ImplementedCheck.class));
Object check = factory.getCheck(activeRule);
assertThat(((ImplementedCheck) check).getMax(), is(300));
@@ -136,7 +140,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("max", "300");
- AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithUnsupportedPropertyType.class));
+ AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithUnsupportedPropertyType.class));
}
@Test
@@ -147,7 +151,7 @@ public class AnnotationCheckFactoryTest {
ActiveRule activeRule = profile.activateRule(rule, null);
activeRule.setParameter("maximum", "300");
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithOverriddenPropertyKey.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithOverriddenPropertyKey.class));
Object check = factory.getCheck(activeRule);
assertThat(((CheckWithOverriddenPropertyKey) check).getMax(), is(300));
@@ -161,7 +165,7 @@ public class AnnotationCheckFactoryTest {
profile.activateRule(rule, null);
profile.activateRule(clonedRule, null);
- AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class>asList(CheckWithKey.class));
+ AnnotationCheckFactory factory = AnnotationCheckFactory.create(profile, "repo", Arrays.<Class> asList(CheckWithKey.class));
assertThat(factory.getChecks(), (Matcher) not(hasItems(nullValue())));
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
index 1b5fd1bd339..358f3898a2d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
@@ -30,8 +30,6 @@ import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.utils.ValidationMessages;
-import java.io.UnsupportedEncodingException;
-
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
@@ -44,7 +42,7 @@ import static org.mockito.Mockito.when;
public class XMLProfileParserTest {
@Test
- public void importProfile() throws UnsupportedEncodingException {
+ public void importProfile() {
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = parse("importProfile.xml", validation);
@@ -56,7 +54,7 @@ public class XMLProfileParserTest {
}
@Test
- public void nameAndLanguageShouldBeMandatory() throws UnsupportedEncodingException {
+ public void nameAndLanguageShouldBeMandatory() {
ValidationMessages validation = ValidationMessages.create();
parse("nameAndLanguageShouldBeMandatory.xml", validation);
@@ -65,7 +63,7 @@ public class XMLProfileParserTest {
}
@Test
- public void importProfileWithRuleParameters() throws UnsupportedEncodingException {
+ public void importProfileWithRuleParameters() {
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = parse("importProfileWithRuleParameters.xml", validation);
@@ -77,7 +75,7 @@ public class XMLProfileParserTest {
}
@Test
- public void importProfileWithUnknownRuleParameter() throws UnsupportedEncodingException {
+ public void importProfileWithUnknownRuleParameter() {
ValidationMessages validation = ValidationMessages.create();
RulesProfile profile = parse("importProfileWithUnknownRuleParameter.xml", validation);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
index 402c1be457f..afe33c33f22 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
@@ -24,12 +24,15 @@ import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
public class JavaFileTest {
@@ -121,7 +124,7 @@ public class JavaFileTest {
}
@Test
- public void oneLevelPackage() throws IOException {
+ public void oneLevelPackage() {
JavaFile clazz = new JavaFile("onelevel.MyFile");
assertEquals("onelevel.MyFile", clazz.getKey());
assertEquals("onelevel", clazz.getParent().getKey());
@@ -140,9 +143,8 @@ public class JavaFileTest {
assertThat((javaFile.getParent()).isDefault(), is(false));
}
-
@Test
- public void shouldResolveClassFromAbsolutePath() throws IOException {
+ public void shouldResolveClassFromAbsolutePath() {
File sources1 = newDir("source1");
File sources2 = newDir("source2");
List<File> sources = Arrays.asList(sources1, sources2);
@@ -154,7 +156,7 @@ public class JavaFileTest {
}
@Test
- public void shouldResolveFromAbsolutePathEvenIfDefaultPackage() throws IOException {
+ public void shouldResolveFromAbsolutePathEvenIfDefaultPackage() {
File source1 = newDir("source1");
File source2 = newDir("source2");
List<File> sources = Arrays.asList(source1, source2);
@@ -167,14 +169,14 @@ public class JavaFileTest {
}
@Test
- public void shouldResolveOnlyJavaFromAbsolutePath() throws IOException {
+ public void shouldResolveOnlyJavaFromAbsolutePath() {
File source1 = newDir("source1");
List<File> sources = Arrays.asList(source1);
assertNull(JavaFile.fromAbsolutePath(absPath(source1, "foo/bar/my_file.sql"), sources, false));
}
@Test
- public void shouldNotFailWhenResolvingUnknownClassFromAbsolutePath() throws IOException {
+ public void shouldNotFailWhenResolvingUnknownClassFromAbsolutePath() {
File source1 = newDir("source1");
List<File> sources = Arrays.asList(source1);
assertNull(JavaFile.fromAbsolutePath("/home/other/src/main/java/foo/bar/MyClass.java", sources, false));
@@ -220,12 +222,11 @@ public class JavaFileTest {
assertFalse(unitTest.matchFilePattern("**/*"));
}
-
- private File newDir(String dirName) throws IOException {
+ private File newDir(String dirName) {
return tempFolder.newFolder(dirName);
}
- private String absPath(File dir, String filePath) throws IOException {
+ private String absPath(File dir, String filePath) {
return new File(dir, filePath).getPath();
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
index 33aa87599f3..70675cbcab1 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
@@ -38,7 +38,7 @@ public class KeyValueFormatTest {
@Test
public void shouldFormatMapOfStrings() {
- Map<String,String> map = Maps.newLinkedHashMap();
+ Map<String, String> map = Maps.newLinkedHashMap();
map.put("lucky", "luke");
map.put("aste", "rix");
String s = KeyValueFormat.format(map);
@@ -47,7 +47,7 @@ public class KeyValueFormatTest {
@Test
public void shouldFormatMapOfIntegerString() {
- Map<Integer,String> map = Maps.newLinkedHashMap();
+ Map<Integer, String> map = Maps.newLinkedHashMap();
map.put(3, "three");
map.put(5, "five");
String s = KeyValueFormat.formatIntString(map);
@@ -56,7 +56,7 @@ public class KeyValueFormatTest {
@Test
public void shouldFormatMapOfIntDouble() {
- Map<Integer,Double> map = Maps.newLinkedHashMap();
+ Map<Integer, Double> map = Maps.newLinkedHashMap();
map.put(13, 2.0);
map.put(5, 5.75);
String s = KeyValueFormat.formatIntDouble(map);
@@ -65,7 +65,7 @@ public class KeyValueFormatTest {
@Test
public void shouldSetEmptyFieldWhenNullValue() {
- Map<Integer,Double> map = Maps.newLinkedHashMap();
+ Map<Integer, Double> map = Maps.newLinkedHashMap();
map.put(13, null);
map.put(5, 5.75);
String s = KeyValueFormat.formatIntDouble(map);
@@ -74,14 +74,14 @@ public class KeyValueFormatTest {
@Test
public void shouldFormatBlank() {
- Map<Integer,String> map = Maps.newTreeMap();
+ Map<Integer, String> map = Maps.newTreeMap();
String s = KeyValueFormat.formatIntString(map);
assertThat(s, is(""));
}
@Test
public void shouldFormatDate() throws ParseException {
- Map<Integer,Date> map = Maps.newLinkedHashMap();
+ Map<Integer, Date> map = Maps.newLinkedHashMap();
map.put(4, new SimpleDateFormat("yyyy-MM-dd").parse("2010-12-25"));
map.put(20, new SimpleDateFormat("yyyy-MM-dd").parse("2009-05-28"));
map.put(12, null);
@@ -90,29 +90,29 @@ public class KeyValueFormatTest {
}
@Test
- public void shouldParseStrings() throws ParseException {
- Map<String,String> map = KeyValueFormat.parse("one=un;two=deux");
+ public void shouldParseStrings() {
+ Map<String, String> map = KeyValueFormat.parse("one=un;two=deux");
assertThat(map.size(), is(2));
assertThat(map.get("one"), is("un"));
assertThat(map.get("two"), is("deux"));
- assertThat(map.keySet().iterator().next(), is("one"));//same order as in string
+ assertThat(map.keySet().iterator().next(), is("one"));// same order as in string
}
@Test
- public void shouldParseBlank() throws ParseException {
- Map<String,String> map = KeyValueFormat.parse("");
+ public void shouldParseBlank() {
+ Map<String, String> map = KeyValueFormat.parse("");
assertThat(map.size(), is(0));
}
@Test
- public void shouldParseNull() throws ParseException {
- Map<String,String> map = KeyValueFormat.parse(null);
+ public void shouldParseNull() {
+ Map<String, String> map = KeyValueFormat.parse(null);
assertThat(map.size(), is(0));
}
@Test
- public void shouldParseEmptyFields() throws ParseException {
- Map<Integer,Double> map = KeyValueFormat.parseIntDouble("4=4.2;2=;6=6.68");
+ public void shouldParseEmptyFields() {
+ Map<Integer, Double> map = KeyValueFormat.parseIntDouble("4=4.2;2=;6=6.68");
assertThat(map.size(), is(3));
assertThat(map.get(4), is(4.2));
assertThat(map.get(2), nullValue());
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java
index e10c61170e4..551905382b8 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java
@@ -19,17 +19,16 @@
*/
package org.sonar.api.utils;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
import org.junit.Before;
import org.junit.Test;
-import java.io.IOException;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
public class ServerHttpClientTest {
- private String serverUrl = "http://test";
-
+ private final String serverUrl = "http://test";
+
private ServerHttpClient serverHttpClient;
@Before
@@ -38,7 +37,7 @@ public class ServerHttpClientTest {
}
@Test
- public void shouldReturnAValidResult() throws IOException {
+ public void shouldReturnAValidResult() {
final String validContent = "valid";
ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl) {
@Override
@@ -57,7 +56,7 @@ public class ServerHttpClientTest {
}
@Test(expected = ServerHttpClient.ServerApiEmptyContentException.class)
- public void shouldThrowAnExceptionIfResultIsEmpty() throws IOException {
+ public void shouldThrowAnExceptionIfResultIsEmpty() {
final String invalidContent = " ";
ServerHttpClient serverHttpClient = new ServerHttpClient(serverUrl) {
@Override
diff --git a/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java b/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
index 77e05930a46..59a508012b5 100644
--- a/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
+++ b/sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
@@ -26,13 +26,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.charts.Chart;
import org.sonar.api.charts.ChartParameters;
-import org.sonar.server.charts.deprecated.*;
+import org.sonar.server.charts.deprecated.BarChart;
+import org.sonar.server.charts.deprecated.BaseChartWeb;
+import org.sonar.server.charts.deprecated.CustomBarChart;
+import org.sonar.server.charts.deprecated.DeprecatedChart;
+import org.sonar.server.charts.deprecated.PieChart;
+import org.sonar.server.charts.deprecated.SparkLinesChart;
import org.sonar.server.platform.Platform;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
@@ -103,7 +109,7 @@ public class ChartsServlet extends HttpServlet {
return false;
}
- public void deprecatedDoGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ public void deprecatedDoGet(HttpServletRequest request, HttpServletResponse response) {
Map<String, String> params = Maps.newHashMap();
params.put(BaseChartWeb.CHART_PARAM_TYPE, request.getParameter(BaseChartWeb.CHART_PARAM_TYPE));
params.put(BaseChartWeb.CHART_PARAM_VALUES, request.getParameter(BaseChartWeb.CHART_PARAM_VALUES));
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java
index 279990f6da2..7debaede4b0 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java
@@ -28,9 +28,9 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.platform.ServerFileSystem;
-import org.sonar.server.plugins.ClassLoaderUtils;
import javax.annotation.Nullable;
+
import java.io.File;
import java.io.IOException;
@@ -44,15 +44,15 @@ public class ApplicationDeployer {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationDeployer.class);
private static final String ROR_PATH = "org/sonar/ror/";
- private ServerFileSystem fileSystem;
- private PluginRepository pluginRepository;
+ private final ServerFileSystem fileSystem;
+ private final PluginRepository pluginRepository;
public ApplicationDeployer(ServerFileSystem fileSystem, PluginRepository pluginRepository) {
this.fileSystem = fileSystem;
this.pluginRepository = pluginRepository;
}
- public void start() throws IOException {
+ public void start() {
deployRubyRailsApps();
}
diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
index df05348967d..79618d14160 100644
--- a/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
+++ b/sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
@@ -45,9 +45,9 @@ public class PluginDeployer implements ServerComponent {
private static final Logger LOG = LoggerFactory.getLogger(PluginDeployer.class);
- private DefaultServerFileSystem fileSystem;
- private Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap();
- private PluginInstaller installer;
+ private final DefaultServerFileSystem fileSystem;
+ private final Map<String, PluginMetadata> pluginByKeys = Maps.newHashMap();
+ private final PluginInstaller installer;
public PluginDeployer(DefaultServerFileSystem fileSystem) {
this(fileSystem, new PluginInstaller());
@@ -58,7 +58,7 @@ public class PluginDeployer implements ServerComponent {
this.installer = installer;
}
- public void start() throws IOException {
+ public void start() {
TimeProfiler profiler = new TimeProfiler().start("Install plugins");
deleteUninstalledPlugins();
@@ -83,13 +83,13 @@ public class PluginDeployer implements ServerComponent {
}
}
- private void loadUserPlugins() throws IOException {
+ private void loadUserPlugins() {
for (File file : fileSystem.getUserPlugins()) {
registerPlugin(file, false, false);
}
}
- private void registerPlugin(File file, boolean isCore, boolean canDelete) throws IOException {
+ private void registerPlugin(File file, boolean isCore, boolean canDelete) {
DefaultPluginMetadata metadata = installer.extractMetadata(file, isCore);
if (StringUtils.isNotBlank(metadata.getKey())) {
PluginMetadata existing = pluginByKeys.get(metadata.getKey());
@@ -100,16 +100,16 @@ public class PluginDeployer implements ServerComponent {
} else {
throw new ServerStartException("Found two plugins with the same key '" + metadata.getKey() + "': " + metadata.getFile().getName() + " and "
- + existing.getFile().getName());
+ + existing.getFile().getName());
}
}
pluginByKeys.put(metadata.getKey(), metadata);
}
}
- private void moveAndLoadDownloadedPlugins() throws IOException {
+ private void moveAndLoadDownloadedPlugins() {
if (fileSystem.getDownloadedPluginsDir().exists()) {
- Collection<File> jars = FileUtils.listFiles(fileSystem.getDownloadedPluginsDir(), new String[]{"jar"}, false);
+ Collection<File> jars = FileUtils.listFiles(fileSystem.getDownloadedPluginsDir(), new String[] {"jar"}, false);
for (File jar : jars) {
File movedJar = moveDownloadedFile(jar);
if (movedJar != null) {
@@ -137,7 +137,7 @@ public class PluginDeployer implements ServerComponent {
}
}
- private void loadCorePlugins() throws IOException {
+ private void loadCorePlugins() {
for (File file : fileSystem.getCorePlugins()) {
registerPlugin(file, true, false);
}
@@ -145,7 +145,7 @@ public class PluginDeployer implements ServerComponent {
public void uninstall(String pluginKey) {
PluginMetadata metadata = pluginByKeys.get(pluginKey);
- if (metadata != null && !metadata.isCore()) {
+ if ((metadata != null) && !metadata.isCore()) {
try {
File masterFile = new File(fileSystem.getUserPluginsDir(), metadata.getFile().getName());
FileUtils.moveFileToDirectory(masterFile, fileSystem.getRemovedPluginsDir(), true);
@@ -158,7 +158,7 @@ public class PluginDeployer implements ServerComponent {
public List<String> getUninstalls() {
List<String> names = Lists.newArrayList();
if (fileSystem.getRemovedPluginsDir().exists()) {
- List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[]{"jar"}, false);
+ List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[] {"jar"}, false);
for (File file : files) {
names.add(file.getName());
}
@@ -168,7 +168,7 @@ public class PluginDeployer implements ServerComponent {
public void cancelUninstalls() {
if (fileSystem.getRemovedPluginsDir().exists()) {
- List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[]{"jar"}, false);
+ List<File> files = (List<File>) FileUtils.listFiles(fileSystem.getRemovedPluginsDir(), new String[] {"jar"}, false);
for (File file : files) {
try {
FileUtils.moveFileToDirectory(file, fileSystem.getUserPluginsDir(), false);
diff --git a/sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java b/sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java
index f63a4db874a..0942759291a 100644
--- a/sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java
@@ -25,10 +25,16 @@ import org.jfree.chart.ChartUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JPanel;
+
+import java.awt.Dimension;
+import java.awt.Graphics;
import java.awt.image.BufferedImage;
-import java.io.*;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -58,7 +64,7 @@ public abstract class BaseChartTest extends TestCase {
}
- protected static void displayTestPanel(BufferedImage image) throws IOException {
+ protected static void displayTestPanel(BufferedImage image) {
ApplicationFrame frame = new ApplicationFrame("testframe");
BufferedPanel imgPanel = new BufferedPanel(image);
frame.setContentPane(imgPanel);
@@ -73,7 +79,7 @@ public abstract class BaseChartTest extends TestCase {
}
private static class BufferedPanel extends JPanel {
- private BufferedImage chartImage;
+ private final BufferedImage chartImage;
public BufferedPanel(BufferedImage chartImage) {
this.chartImage = chartImage;
diff --git a/sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java b/sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java
index 0a30afe4b1b..7f251513619 100644
--- a/sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java
@@ -22,7 +22,6 @@ package org.sonar.server.filters;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Test;
-import java.text.ParseException;
import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
@@ -30,7 +29,7 @@ import static org.junit.Assert.assertThat;
public class DateCriterionTest {
@Test
- public void ignoreTime() throws ParseException {
+ public void ignoreTime() {
DateCriterion criterion = new DateCriterion().setDate(3);
Date date = criterion.getDate();
assertThat(date.getHours(), is(0));
@@ -38,7 +37,7 @@ public class DateCriterionTest {
}
@Test
- public void testDaysAgo() throws ParseException {
+ public void testDaysAgo() {
DateCriterion criterion = new DateCriterion().setDate(3);
Date date = criterion.getDate();
assertThat(date.getMinutes(), is(0));
diff --git a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
index 65727c2a8c7..0fefc603f25 100644
--- a/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
@@ -37,14 +37,14 @@ public class ServerSettingsTest extends AbstractDbUnitTestCase {
private static File home = getHome();
@Test
- public void shouldLoadPropertiesFile() throws URISyntaxException {
+ public void shouldLoadPropertiesFile() {
ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
assertThat(settings.getString("hello"), is("world"));
}
@Test
- public void systemPropertiesShouldOverridePropertiesFile() throws URISyntaxException {
+ public void systemPropertiesShouldOverridePropertiesFile() {
System.setProperty("ServerSettingsTestEnv", "in_env");
ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
@@ -58,7 +58,7 @@ public class ServerSettingsTest extends AbstractDbUnitTestCase {
}
@Test
- public void shouldActivateDatabaseSettings() throws URISyntaxException {
+ public void shouldActivateDatabaseSettings() {
setupData("db/shared");
ServerSettings settings = new ServerSettings(new PropertyDefinitions(), new BaseConfiguration(), new File("."), home);
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
index d053aab5074..0259f232692 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.server.plugins;
-import org.apache.commons.io.FileUtils;
import org.hamcrest.core.Is;
import org.junit.After;
import org.junit.Test;
@@ -29,6 +28,7 @@ import org.sonar.api.ServerExtension;
import org.sonar.api.SonarPlugin;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.test.TestUtils;
import java.io.File;
import java.util.Arrays;
@@ -56,7 +56,7 @@ public class DefaultServerPluginRepositoryTest {
@Test
public void testStart() {
PluginDeployer deployer = mock(PluginDeployer.class);
- File pluginFile = FileUtils.toFile(getClass().getResource("/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar"));
+ File pluginFile = TestUtils.getResource("/org/sonar/server/plugins/DefaultServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar");
PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
.setKey("artifactsize")
.setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
@@ -90,7 +90,7 @@ public class DefaultServerPluginRepositoryTest {
newMetadata("checkstyle", null),
newMetadata("checkstyle-extensions", "checkstyle"),
newMetadata("sqale", null)
- );
+ );
when(deployer.getMetadata()).thenReturn(metadata);
DefaultServerPluginRepository repository = new DefaultServerPluginRepository(deployer);
@@ -108,7 +108,7 @@ public class DefaultServerPluginRepositoryTest {
newMetadata("checkstyle", null),
newMetadata("checkstyle-extensions", "checkstyle"),
newMetadata("sqale", null)
- );
+ );
when(deployer.getMetadata()).thenReturn(metadata);
DefaultServerPluginRepository repository = new DefaultServerPluginRepository(deployer);
@@ -126,13 +126,13 @@ public class DefaultServerPluginRepositoryTest {
}
public static class FakePlugin extends SonarPlugin {
- private List<Class> extensions;
+ private final List<Class> extensions;
public FakePlugin(List<Class> extensions) {
this.extensions = extensions;
}
- public List getExtensions() {
+ public List<Class> getExtensions() {
return extensions;
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
index 09122665844..6adefb336f9 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
@@ -31,8 +31,6 @@ import org.sonar.server.platform.ServerStartException;
import org.sonar.test.TestUtils;
import java.io.File;
-import java.io.IOException;
-import java.text.ParseException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
@@ -49,7 +47,7 @@ public class PluginDeployerTest {
public TestName name = new TestName();
@Before
- public void start() throws ParseException {
+ public void start() {
homeDir = TestUtils.getResource(PluginDeployerTest.class, name.getMethodName());
deployDir = TestUtils.getTestTempDir(PluginDeployerTest.class, name.getMethodName() + "/deploy");
fileSystem = new DefaultServerFileSystem(null, homeDir, deployDir);
@@ -58,7 +56,7 @@ public class PluginDeployerTest {
}
@Test
- public void deployPlugin() throws IOException {
+ public void deployPlugin() {
deployer.start();
// check that the plugin is registered
@@ -69,7 +67,7 @@ public class PluginDeployerTest {
assertThat(plugin.getDeployedFiles().size(), is(1));
assertThat(plugin.isCore(), is(false));
assertThat(plugin.isUseChildFirstClassLoader(), is(false));
-
+
// check that the file is deployed
File deployedJar = new File(deployDir, "plugins/foo/foo-plugin.jar");
assertThat(deployedJar.exists(), is(true));
@@ -77,7 +75,7 @@ public class PluginDeployerTest {
}
@Test
- public void deployDeprecatedPlugin() throws IOException, ClassNotFoundException {
+ public void deployDeprecatedPlugin() {
deployer.start();
// check that the plugin is registered
@@ -94,10 +92,10 @@ public class PluginDeployerTest {
}
@Test
- public void deployPluginExtensions() throws IOException {
+ public void deployPluginExtensions() {
deployer.start();
- // check that the plugin is registered
+ // check that the plugin is registered
assertThat(deployer.getMetadata().size(), Is.is(1)); // no more checkstyle
PluginMetadata plugin = deployer.getMetadata("foo");
@@ -112,19 +110,19 @@ public class PluginDeployerTest {
}
@Test
- public void ignoreJarsWhichAreNotPlugins() throws IOException {
+ public void ignoreJarsWhichAreNotPlugins() {
deployer.start();
assertThat(deployer.getMetadata().size(), Is.is(0));
}
@Test(expected = ServerStartException.class)
- public void failIfTwoPluginsWithSameKey() throws IOException {
+ public void failIfTwoPluginsWithSameKey() {
deployer.start();
}
@Test(expected = ServerStartException.class)
- public void failIfTwoDeprecatedPluginsWithSameKey() throws IOException {
+ public void failIfTwoDeprecatedPluginsWithSameKey() {
deployer.start();
}
diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java
index a748f58e58f..c5725717e16 100644
--- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java
@@ -71,7 +71,7 @@ public class ServerExtensionInstallerTest {
this.extensions = extensions;
}
- public List getExtensions() {
+ public List<Class> getExtensions() {
return extensions;
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java b/sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java
index 67479445563..0a8358b154e 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java
@@ -25,7 +25,6 @@ import org.sonar.api.platform.ServerUpgradeStatus;
import org.sonar.core.persistence.DatabaseVersion;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import java.sql.SQLException;
import java.util.List;
import static org.hamcrest.Matchers.is;
@@ -37,7 +36,7 @@ import static org.mockito.Mockito.when;
public class DeleteDeprecatedMeasuresTest extends AbstractDbUnitTestCase {
@Test
- public void shouldDeleteMeasuresWithCategory() throws SQLException {
+ public void shouldDeleteMeasuresWithCategory() {
setupData("sharedFixture");
ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
@@ -50,7 +49,7 @@ public class DeleteDeprecatedMeasuresTest extends AbstractDbUnitTestCase {
}
@Test
- public void shouldDeleteMeasuresWithPriority() throws SQLException {
+ public void shouldDeleteMeasuresWithPriority() {
setupData("sharedFixture");
ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
index 45bff9e6ea8..3bf2e7984ad 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
@@ -19,20 +19,19 @@
*/
package org.sonar.server.startup;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
import org.junit.Test;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
import org.sonar.jpa.dao.MeasuresDao;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
public class RegisterMetricsTest extends AbstractDbUnitTestCase {
@Test
@@ -59,7 +58,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
}
@Test
- public void enableOnlyLoadedMetrics() throws SQLException {
+ public void enableOnlyLoadedMetrics() {
setupData("enableOnlyLoadedMetrics");
RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
@@ -70,7 +69,7 @@ public class RegisterMetricsTest extends AbstractDbUnitTestCase {
}
@Test
- public void cleanAlerts() throws SQLException {
+ public void cleanAlerts() {
setupData("cleanAlerts");
RegisterMetrics loader = new RegisterMetrics(getSession(), new MeasuresDao(getSession()), null);
diff --git a/sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java b/sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java
index fa0ac3fcf54..61f19939c6c 100644
--- a/sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java
+++ b/sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java
@@ -32,7 +32,7 @@ public class StringArrayReaderTest {
@Test
public void read() throws IOException {
- String[] lines = { "import java.util.*;", "//NOSONAR comment", };
+ String[] lines = {"import java.util.*;", "//NOSONAR comment",};
StringArrayReader reader = new StringArrayReader(lines);
assertEquals('i', reader.read());
assertEquals('m', reader.read());
@@ -40,7 +40,7 @@ public class StringArrayReaderTest {
@Test
public void testLFEndOfLineDelimiter() throws IOException {
- String[] lines = { ";", ";", };
+ String[] lines = {";", ";",};
StringArrayReader reader = new StringArrayReader(lines, EndOfLineDelimiter.LF);
assertEquals(';', reader.read());
assertEquals('\n', reader.read());
@@ -49,7 +49,7 @@ public class StringArrayReaderTest {
@Test
public void testCREndOfLineDelimiter() throws IOException {
- String[] lines = { ";", ";", };
+ String[] lines = {";", ";",};
StringArrayReader reader = new StringArrayReader(lines, EndOfLineDelimiter.CR);
assertEquals(';', reader.read());
assertEquals('\r', reader.read());
@@ -58,7 +58,7 @@ public class StringArrayReaderTest {
@Test
public void testCRPlusLFEndOfLineDelimiter() throws IOException {
- String[] lines = { ";", ";", };
+ String[] lines = {";", ";",};
StringArrayReader reader = new StringArrayReader(lines, EndOfLineDelimiter.CR_PLUS_LF);
assertEquals(';', reader.read());
assertEquals('\r', reader.read());
@@ -68,13 +68,13 @@ public class StringArrayReaderTest {
@Test
public void ready() throws IOException {
- String[] lines = { ";", "//NOSONAR", };
+ String[] lines = {";", "//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
assertTrue(reader.ready());
}
@Test
- public void markSupported() throws IOException {
+ public void markSupported() {
String[] lines = {};
StringArrayReader reader = new StringArrayReader(lines);
assertTrue(reader.markSupported());
@@ -82,7 +82,7 @@ public class StringArrayReaderTest {
@Test
public void mark() throws IOException {
- String[] lines = { ";", "//NOSONAR", };
+ String[] lines = {";", "//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
reader.read(new char[4], 0, 4);
reader.mark(4);
@@ -94,7 +94,7 @@ public class StringArrayReaderTest {
@Test(expected = IOException.class)
public void close() throws IOException {
- String[] lines = { ";", "//NOSONAR", };
+ String[] lines = {";", "//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
assertTrue(reader.ready());
reader.close();
@@ -103,7 +103,7 @@ public class StringArrayReaderTest {
@Test
public void readEndOfArray() throws IOException {
- String[] lines = { ";" };
+ String[] lines = {";"};
StringArrayReader reader = new StringArrayReader(lines);
assertEquals(';', reader.read());
assertEquals(-1, reader.read());
@@ -111,7 +111,7 @@ public class StringArrayReaderTest {
@Test
public void readMultipleCharacters() throws IOException {
- String[] lines = { ";", "//NOSONAR", };
+ String[] lines = {";", "//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
char[] chars = new char[4];
assertEquals(4, reader.read(chars, 0, 4));
@@ -120,7 +120,7 @@ public class StringArrayReaderTest {
@Test
public void readMultipleCharactersTillEndOfArray() throws IOException {
- String[] lines = { ";", "//NOSONAR", };
+ String[] lines = {";", "//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
char[] chars = new char[11];
assertEquals(11, reader.read(chars, 0, 11));
@@ -137,7 +137,7 @@ public class StringArrayReaderTest {
@Test
public void readMultipleCharactersWithEmptyLineAtEnd() throws IOException {
- String[] lines = { ";", "//NOSONAR", "", "" };
+ String[] lines = {";", "//NOSONAR", "", ""};
StringArrayReader reader = new StringArrayReader(lines);
char[] cbuf = new char[10000];
assertEquals(13, reader.read(cbuf, 0, 10000));
@@ -146,7 +146,7 @@ public class StringArrayReaderTest {
@Test
public void readOneCharacter() throws IOException {
- String[] lines = { ";", "//NOSONAR" };
+ String[] lines = {";", "//NOSONAR"};
StringArrayReader reader = new StringArrayReader(lines);
char[] chars = new char[1];
assertEquals(1, reader.read(chars, 0, 1));
@@ -155,7 +155,7 @@ public class StringArrayReaderTest {
@Test
public void readBlankLines() throws IOException {
- String[] lines = { "", "", "" };
+ String[] lines = {"", "", ""};
StringArrayReader reader = new StringArrayReader(lines);
assertEquals('\n', reader.read());
assertEquals('\n', reader.read());
@@ -164,7 +164,7 @@ public class StringArrayReaderTest {
@Test
public void skip() throws IOException {
- String[] lines = { "//NOSONAR", };
+ String[] lines = {"//NOSONAR",};
StringArrayReader reader = new StringArrayReader(lines);
reader.skip(2);
assertEquals('N', reader.read());
@@ -176,7 +176,7 @@ public class StringArrayReaderTest {
StringArrayReader reader = new StringArrayReader(emptyLines);
assertEquals(-1, reader.read());
- String[] lines = { "a" };
+ String[] lines = {"a"};
reader = new StringArrayReader(lines);
assertEquals('a', reader.read());
assertEquals(-1, reader.read());
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java
index e9954b6652c..f3a037f9338 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java
@@ -20,8 +20,6 @@
package org.sonar.wsclient.services;
import org.junit.Test;
-import org.sonar.wsclient.Sonar;
-
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
index eff761bf747..9ee26b67530 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
@@ -26,9 +26,7 @@ import java.util.List;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
public class ManualMeasureUnmarshallerTest extends UnmarshallerTestCase {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java
index 1cd63ee51a8..f60c0506d65 100644
--- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java
@@ -20,7 +20,6 @@
package org.sonar.wsclient.unmarshallers;
import org.junit.Test;
-import org.sonar.wsclient.services.Server;
import org.sonar.wsclient.services.ServerSetup;
import static org.hamcrest.CoreMatchers.nullValue;