]> source.dussan.org Git - sonarqube.git/commitdiff
Remove warnings
authorDavid Gageot <david@gageot.net>
Tue, 24 Apr 2012 08:12:28 +0000 (10:12 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 27 Apr 2012 12:58:59 +0000 (14:58 +0200)
92 files changed:
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java
plugins/sonar-checkstyle-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstylePlugin.java
plugins/sonar-checkstyle-plugin/src/test/java/org/sonar/plugins/checkstyle/CheckstyleConfigurationTest.java
plugins/sonar-cobertura-plugin/src/main/java/org/sonar/plugins/cobertura/CoberturaPlugin.java
plugins/sonar-cobertura-plugin/src/test/java/org/sonar/plugins/cobertura/CoberturaSensorTest.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/GenerateAlertEventsTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProfileEventsSensorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/VersionEventsSensorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/ViolationTrackingDecoratorTest.java
plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdPlugin.java
plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/PmdEngineTest.java
plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DbCleanerPlugin.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/DbCleanerTestUtils.java
plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest.java
plugins/sonar-design-plugin/src/main/java/org/sonar/plugins/design/DesignPlugin.java
plugins/sonar-design-plugin/src/test/java/org/sonar/plugins/design/batch/DsmSerializerTest.java
plugins/sonar-email-notifications-plugin/src/main/java/org/sonar/plugins/emailnotifications/EmailNotificationsPlugin.java
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsPlugin.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsProfileImporterTest.java
plugins/sonar-jacoco-plugin/src/main/java/org/sonar/plugins/jacoco/JaCoCoPlugin.java
plugins/sonar-l10n-en-plugin/src/main/java/org/sonar/plugins/l10n/EnglishPackPlugin.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdPlugin.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdProfileExporterTest.java
plugins/sonar-squid-java-plugin/src/main/java/org/sonar/plugins/squid/SquidPlugin.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/JavaAstScannerTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/PackageVisitorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/JavaSourceImporterTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidExecutorTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/SquidTestUtils.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/BridgeTestCase.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/ChidamberKemererBridgeTest.java
plugins/sonar-squid-java-plugin/src/test/java/org/sonar/plugins/squid/bridges/DsmSerializerTest.java
plugins/sonar-surefire-plugin/src/main/java/org/sonar/plugins/surefire/SurefirePlugin.java
plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/data/SurefireStaxHandlerTest.java
sonar-application/src/main/java/org/sonar/application/JettyEmbedder.java
sonar-batch/src/main/java/org/sonar/batch/ProjectTree.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/JdbcDriverHolder.java
sonar-batch/src/test/java/org/sonar/batch/DefaultProjectFileSystem2Test.java
sonar-batch/src/test/java/org/sonar/batch/MavenProjectConverterTest.java
sonar-batch/src/test/java/org/sonar/batch/ProjectTreeTest.java
sonar-batch/src/test/java/org/sonar/batch/ServerMetadataTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ProjectExtensionInstallerTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/TempDirectoriesTest.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByDaysTest.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysisTest.java
sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotFinderTest.java
sonar-batch/src/test/java/org/sonar/batch/index/DefaultResourcePersisterTest.java
sonar-check-api/src/test/java/org/sonar/check/AnnotationIntrospectorTest.java
sonar-colorizer/src/test/java/org/sonar/colorizer/UserGuideTest.java
sonar-core/src/main/java/org/sonar/core/persistence/MyBatis.java
sonar-core/src/test/java/org/sonar/core/persistence/DefaultDatabaseTest.java
sonar-core/src/test/java/org/sonar/core/persistence/InMemoryDatabaseTest.java
sonar-core/src/test/java/org/sonar/core/persistence/MyBatisTest.java
sonar-duplications/src/test/java/net/sourceforge/pmd/cpd/AbstractLanguageTest.java
sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java
sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java
sonar-graph/src/test/java/org/sonar/graph/DsmTopologicalSorterTest.java
sonar-graph/src/test/java/org/sonar/graph/IncrementalCyclesAndFESSolverTest.java
sonar-gwt-api/src/main/java/org/sonar/gwt/ui/Page.java
sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/AnnotationProfileParser.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/charts/AbstractChartTest.java
sonar-plugin-api/src/test/java/org/sonar/api/checks/AnnotationCheckFactoryTest.java
sonar-plugin-api/src/test/java/org/sonar/api/profiles/XMLProfileParserTest.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/JavaFileTest.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/KeyValueFormatTest.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/ServerHttpClientTest.java
sonar-server/src/main/java/org/sonar/server/charts/ChartsServlet.java
sonar-server/src/main/java/org/sonar/server/plugins/ApplicationDeployer.java
sonar-server/src/main/java/org/sonar/server/plugins/PluginDeployer.java
sonar-server/src/test/java/org/sonar/server/charts/deprecated/BaseChartTest.java
sonar-server/src/test/java/org/sonar/server/filters/DateCriterionTest.java
sonar-server/src/test/java/org/sonar/server/platform/ServerSettingsTest.java
sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
sonar-server/src/test/java/org/sonar/server/plugins/PluginDeployerTest.java
sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java
sonar-server/src/test/java/org/sonar/server/startup/DeleteDeprecatedMeasuresTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterMetricsTest.java
sonar-squid/src/test/java/org/sonar/squid/text/StringArrayReaderTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/services/ProjectDeleteQueryTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ManualMeasureUnmarshallerTest.java
sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerSetupUnmarshallerTest.java

index 803dfc1ddf90360c2c76afcbfa2f50cc5c795884..550c7e4b1f4542188b03762d38bfd3f5e46cae01 100644 (file)
@@ -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());
index 9bba008989bcdebfbe79b52de7479cd0b1b5b97f..b81a84545782e1ecbed5b965c2fd6f07ae9457c9 100644 (file)
  */
 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);
   }
 }
index 8ab95ac7f9a2f8cfa78e671715e1dce24b054d41..698314871194996a5606bcb4b88b92cdfa2d0870 100644 (file)
@@ -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;
 
index fcea73baa5ec82d5d3dc0513e0b9e94525c799a1..222c2c5ac7741a72766b171d7f758dbd9f886bc6 100644 (file)
  */
 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);
   }
 }
index dd37f433f6211a8a44f26a5672b0ba4e81d297c2..83db39159c6d5e3b0f5a76f38bb713354aec4ac2 100644 (file)
  */
 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"));
index 71c09d25209e5bba182dcfd8e4ff09ea33c6aa01..29764d34fdc73099c562be21131a32b2d957b272 100644 (file)
@@ -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);
index 4e2d41888ab1b9d6dac81dd63ac64dfb185d09ca..f6ccdb668b3dd8408bfa7ef7e89defa6fd3218aa 100644 (file)
  */
 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);
index f0626571a479b8f51b0f32fe99acd2719df125a0..f2b885fb65d516c420757bdb9f13431e0e63a283 100644 (file)
  */
 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);
index 1c8db23ba1980296c63cfb98c9e86ffe922bfd1d..65af02fcab27d9a7d2903f3cb8a88f933c3f9ab9 100644 (file)
  */
 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;
-  }
 }
index 36a0abc05a774c8ff8fd0bd861ecc80c03b8d613..da8bc44ac4c9b1eb7fd7bbd8eba2ae507144065b 100644 (file)
@@ -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);
index 7ec500b954cf66c843d22dd9d9b4456834933a67..911f66ff443e51b5f6fa8f87b85744f013d35c48 100644 (file)
@@ -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));
index 2708f843d17c03a3e115864bd89463571d591f13..9b734290990b3ad0762b9b4440464e650031d3ce 100644 (file)
  */
 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);
   }
 
 }
index 54a86f56063339b51c1f4f25658ccad9701f326a..3bbedf7f7877743f273bf40de42a1fb4c488e17a 100644 (file)
@@ -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() {
index 4507771468f2cea3256d242ebc62b9ce7a2aea1d..6b2921e61a4962b53c09fcc13ac40d5474f82510 100644 (file)
@@ -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);
   }
 }
index 9711b3835338df9304e4834e7482988a99fc4cac..3f7f78810778269052e4894e6945801a03cb859a 100644 (file)
@@ -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() {
index 17317064d31330599d3ae9f1a72e26385ee3182d..bea6ed413b6cfeefa286d074d69ce9e5b1ba656f 100644 (file)
  */
 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);
     }
 
index cb643053bfacae6448f898e2781fa02a293e0802..50805055b42ed0d449047e6782860023bda0a65f 100644 (file)
@@ -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);
   }
 }
index a0a3b8a28fd9603abc1e071c236944808f29db3c..da8a118028992d09a8c1df4e53afffb3e447d476 100644 (file)
@@ -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"));
index 9c8965c2366fc4adaf475a57e6ce6165259905de..49e7befdf7933d24b9d265bd24d334707c56ebf2 100644 (file)
  */
 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,
 
index 070dfbee8bd0a90a27cc063e1ef350207a3ff05b..cb2da99ec37bba423d1f3f2ca6391a69ae477268 100644 (file)
  */
 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);
   }
 }
index 90f9f121a9c58f46a34cf3a1e96d94d858ed13fa..84d233f1e16c110c285933a9eff43c8a61bc839b 100644 (file)
@@ -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);
index fae29ce55efd355280ae449c0ba05d0eb4376cfd..8fd1e6c5cbd32206eba3821e08637b77698e4f86 100644 (file)
  */
 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
index c9040a80febe60de580b79d357fd009fc3c44933..19e8bb2262e27e6b9245a499b7107b53ee55b5b7 100644 (file)
@@ -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();
   }
 }
index 1dbc6a4901e0a6e23f9af3b5487644238444e26f..0f485f897efee4419a1d7f35d285b951cd0e7004 100644 (file)
  */
 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();
index abf8dda044205cf962a85b849462e297faae657d..dff7b9f85bca4401a14053a9af5f2fc3fe64b81c 100644 (file)
  */
 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
-    );
+        );
   }
 }
index dd9feab2cd9aafc2024924cff3c9198c5f610548..a45a7426075fe563497c8257d310087fb7f09840 100644 (file)
@@ -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);
 
index fcbbc68033d8c230a2061a346625077f4f96f152..7dac4cc592e2fc1033e62a105cf669b1fe58472a 100644 (file)
  */
 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;
index 789c0c0d1cf0ee7d26460d010e24d7f6081e04fc..e67b02d531e36860b4d527d855a3730a5dd815fe 100644 (file)
  */
 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,
index 9022282aebaf8f6b44b2148a8804807be346c283..4acbe703fe60daf27f1947213ab81429be69715a 100644 (file)
  */
 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));
index 08f7e4086f58b8194279629ecc62d7ae2a27a484..3ae79a74757f73a6af293815afb359fbebbccb9e 100644 (file)
@@ -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;
index cf02869229d0c6fcdc71f5ba53b9740b5f9247bf..f6c156a508dce589e68713a4aacae13154b4cbcd 100644 (file)
@@ -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;
index 0cd45d4e47348774c484459ad1eab12aaf27ff81..ecc445843b0619b5bee1f601663a3c06a5355c60 100644 (file)
  */
 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());
index 2bbbf210a66a322975de41f7abc8815fc1effbd0..0430ebf4c539a63aa0c5bc5e6a41304a7d9da602 100644 (file)
  */
 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"))));
   }
index a2c6072c4a38325cd56921afedbf67b066c21330..06279dd4d8355dc62149271a3a8d28bf9552c672 100644 (file)
@@ -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());
   }
 }
index 0820183a79ad496e83de1a8ab80740125e26a35a..6c8957cb2873372283d666fc8c17f2becef10357 100644 (file)
  */
 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");
   }
index 966ba8391a3fca0831dbd1573fdd6e4aa608cc87..dd7fb7fc54f78e90c66a7308ebaf006dd901be25 100644 (file)
@@ -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 {
 
index 9c1c1f8f2b10482545b6dfd00b75a0bcd4797409..f6d2d102b745c7f52c3cc7a820a1adcd9b787042 100644 (file)
@@ -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"));
index c076e954fb04b275a939fdb4dcd6a17c1a192a2a..b4eb8cc5e5dc959ee3fb9be2d0cc232887033cab 100644 (file)
  */
 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);
   }
 
 }
index 8cdbe6cf062d4101a76ac9e411a053bd35d36c37..e99590d2712b620cf9f864cd574b423c77dabd1a 100644 (file)
@@ -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 {
 
index 2bbbbd276e7b33c4c67a5189494495acbd09b211..53cdc2aadba8451ecfb488de476a0a1337c63a96 100644 (file)
@@ -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());
index 70d601aa396b4286178cc5b0d68d0c29b3ab3a57..c99fd70d838b0f56cd57110e27bd943b40bfb347 100644 (file)
@@ -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);
index d7e59ef760b417fe2d73ea87789b919dd9283f2d..1cdb7b9217cf83eeb50701cb481d714455bd3446 100644 (file)
@@ -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) {
index 3588c583e23333313b5e0f7aa2d27631396c2d6a..65773cad9053567768cb89d43864cd23b38755cb 100644 (file)
  */
 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));
-
   }
 }
index fe3cf025e9c17f3217695628ecaead566472da6e..38abbf99fd012acc334a245606f6523083191036 100644 (file)
  */
 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);
index 24f913239bd6a347dd69032d8f918e72735ab018..48d36520ff5c5aa033d9d37102a61005b804da6e 100644 (file)
  */
 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());
+  // }
 
 }
index 491d120f39b903611f13afe3080365d9d912e6d0..b0d593f78a252165fd4d31a9e18d757f1b76d2df 100644 (file)
@@ -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/");
 
index c700aa2af4682a4731c9f2ad983646dc1c7c65ec..8fa44b14fbb34c21b0ccd3ba3e7f92171de64138 100644 (file)
@@ -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);
           }
         }
index bb50e80b9a31a5a48f5ace091495fd7116ca0ccf..944eb90977e18b71ab92af79b028a00e459fce13 100644 (file)
@@ -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());
index a7147e1a37dafc2563f6d5124322df2e83c8f8fa..374dc7e8f9269ceb4e83dd4c60a9ef173867a7c1 100644 (file)
  */
 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 {
 
index bc6ca17880418a4909182898732118fc5cd8ea84..c07ca95819802d3ffd3d66dea936df886aea540f 100644 (file)
@@ -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));
   }
index 69c7bc6e6cbba94fee30d7d5f2c07e83053dcb3c..391fc551a44d22bdd90d1704157c7cbd29e648db 100644 (file)
@@ -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));
   }
 
index 7bf1c050d2ecba4faf23b5e88c1a85c3fddb6ae5..e3f12cde8515e3e0970e60c440d790a03e10f486 100644 (file)
  */
 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);
index 54575f1a9057f92dd32e635856804873bdae3267..2ab6d29a945b1019a637d78767ea889c1574e073 100644 (file)
@@ -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"));
   }
 
index c85ca8a895f956181eb8a902540befc3c391de45..03e580d68f17734b9bb04a07f1dee97e85a8886a 100644 (file)
@@ -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");
   }
 
 }
index 3bf47118a8d4907d9d41d80df3544e266af61b6f..0370e8e1ded276c04a0c32256d7cf1a542257f18 100644 (file)
  */
 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 {
index 61d57c7daab33cff5a8c3fef3e8b840f72734d0c..5808a02afeea9506e9f651fdf0433c4bb9b41f1a 100644 (file)
@@ -60,7 +60,7 @@ public class UserGuideTest {
   }
 
   @Test
-  public void defineNewLanguage() throws IOException {
+  public void defineNewLanguage() {
 
   }
 
index 0c2b1b754150960b3007cdd00cadbbdb64ce4497..b0e7dec94fd9bc5e2c56df7e7eec61421e7f1523 100644 (file)
@@ -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");
     }
index 0fc45efaac0eb4baae2250fb4bfe8c681620c519..048c5d3df49db3fd9205a1411af61a07116e4c8c 100644 (file)
@@ -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();
index 23d7bc30be10ba583f49da7e6af46f826c17fab6..3e6bb1b6fa63cd9249ec0a0f02c3c83f6e21b6f5 100644 (file)
@@ -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();
index 1905ded8649dbe88d42c2ce3e66f1ed94cab5ac3..592bca544842ba78be5370768837d1a40f70bfd4 100644 (file)
@@ -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());
index eac34fb50a9cf748feb78ac9711cdc174d6bdde8..404df7166571be2496d5be5709143478d3784d0c 100644 (file)
@@ -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") {
     };
 
index 93a8a604b75c676ecc3fde0b85685289159abc4e..840ad390df037fd19f834011e3bc1efca7d32fc5 100644 (file)
  */
 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);
index 9e225025d8a51b33eadb8287b512bdde0220ee6f..86641ad98fde554963832ee2ad937e95c17b3b0c 100644 (file)
  */
 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);
index 36166eb95cf3094f553acfa44b1fb87d938d56d2..06818fc28567664b1dc800815916c870cec0fd68 100644 (file)
@@ -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);
index a00c4625a8274b7aaae93271dba4704086fb676c..0702e945344f6aa4c3053de2ad36c9f939109a7d 100644 (file)
@@ -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;
 
index cb89b059f41921ae546423fe355fa5dbc4df92f1..34a146b2e76b27c7e5951abfd1f2de476ddf7ac0 100644 (file)
@@ -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;
index 74e1bfe06a43fa7bfb08911f0134630b2cb11f2d..0904ac3a293daa1afe35376ccf4bdefbc18dd74b 100644 (file)
@@ -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);
     }
index de4d4ec82a406b589e6568ecf32e122c9de934a5..07dee384d6134c030888a52cab1a1c9d95f8e854 100644 (file)
@@ -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) {
index da1ffdf3b4771bc818f90c8b700755e6a7849f8b..8c8f876c00b09143a9ec30823a4d01988ecf1db1 100644 (file)
  */
 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());
           }
index d2eacf3eb51e473846bc76f95a5f819cc502c32e..59bc02e835942f01a2a9f08933f6b2c7a18e4bea 100644 (file)
@@ -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
index f7bce23c103bbca0e533c765e8b5bd318687d56e..392df440a20f3f68ad9b74da9b91aa47822b0ead 100644 (file)
  */
 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);
   }
 }
index b92dcfec2f96efc2144943f7c54e60daf9d9b2c8..3016077d07af366389d206881052f9b825a31d5e 100644 (file)
@@ -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;
index 60670a372d3833e13e63579351c486a0ba1bfe82..895e37952e689408d8ef35806e1f747f8ccb79e4 100644 (file)
@@ -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())));
   }
index 1b5fd1bd3396f546ba3687a5fed2ce85b40ecffa..358f3898a2d4eef2eacc69cfffcc55357946f734 100644 (file)
@@ -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);
 
index 402c1be457f5f31ae01596c7a45c416aa9677c42..afe33c33f22cf095e75fc2d921e96e18a5fdd75f 100644 (file)
@@ -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();
   }
 }
index 33aa87599f33a45bdbeaccf10f220d4981b13a9e..70675cbcab141a39e92b8e3f5ee60da951bf254a 100644 (file)
@@ -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());
index e10c61170e4a036d74f89bde012429bd29069473..551905382b825501fe502949328e293827012507 100644 (file)
  */
 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
index 77e05930a4673ccf71667e77cbb104a485416a25..59a508012b5e8b95b52d1566fedbf5bd4758b715 100644 (file)
@@ -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));
index 279990f6da2ca6189ca6019596c27570e330770c..7debaede4b027d9e0deba07441c4173bfd208525 100644 (file)
@@ -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();
   }
 
index df05348967dd6de552d0a2462c1e26e5518ac803..79618d14160471aa13eb2f2234ff87e0e7e62245 100644 (file)
@@ -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);
index f63a4db874a75c3ee155a2179fff50c8744ff596..0942759291abd0fc365b751e10f904d98c83f591 100644 (file)
@@ -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;
index 0a30afe4b1b0ac329261bda25b5bd1e052a34c24..7f2515136198969d02b44be5d49465906822fe18 100644 (file)
@@ -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));
index 65727c2a8c75cbf771ebfb83eb1cc62fd6938559..0fefc603f254156ffde15fef4ca44d4d95ae87c8 100644 (file)
@@ -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);
index d053aab5074a70be2a1ade0926572f9f29231038..0259f2326924e913d9c7ce962da0061789b15273 100644 (file)
@@ -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;
     }
   }
index 0912266584413ed15b03532573aeffa4787f1c35..6adefb336f97b814d67dd9991522dee8e6efc05c 100644 (file)
@@ -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();
   }
 
index a748f58e58f5a4e69220010b77b6279206194bdc..c5725717e16b304265b706a21d7c81fdd3a1092f 100644 (file)
@@ -71,7 +71,7 @@ public class ServerExtensionInstallerTest {
       this.extensions = extensions;
     }
 
-    public List getExtensions() {
+    public List<Class> getExtensions() {
       return extensions;
     }
   }
index 6747944556342abcd4a69326339aedc8b60ef45b..0a8358b154e84971d35aa2c537255d897048866c 100644 (file)
@@ -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);
index 45bff9e6ea81654911abd9dd5eabce8549658e82..3bf2e7984ad95923dd5a11a66ec693a11f6a0cfd 100644 (file)
  */
 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);
index fa0ac3fcf54aa11efb18578312997150d3d1c77d..61f19939c6cbe316f3c79d308a48a674f8c97264 100644 (file)
@@ -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());
index e9954b6652cbea48e2927193e1740e6d9d7a3167..f3a037f9338a6ea3e06df8dc9fee6c61027e53e8 100644 (file)
@@ -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;
 
index eff761bf747b398fe98e1284b87322188b2b4c12..9ee26b6753001a2a8f33c9b5525f50e687ba0dd9 100644 (file)
@@ -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 {
 
index 1cd63ee51a8a1746c6c81c23ff1001fa0e5cfade..f60c0506d6582f34004afa3a06562c9916e17e8f 100644 (file)
@@ -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;