]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 May 2016 18:01:49 +0000 (20:01 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 19 May 2016 18:01:49 +0000 (20:01 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/DefaultStorable.java
sonar-scanner-engine/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java
sonar-scanner-engine/src/test/java/org/sonar/batch/sensor/DefaultSensorStorageTest.java

index 9a87a98663edead667aa1bc7c6d587abf5da4f13..0c39e2d891b21c60e6dbacfd6e70cfa37b715152 100644 (file)
 package org.sonar.api.batch.sensor.internal;
 
 import com.google.common.base.Preconditions;
+import javax.annotation.Nullable;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import org.apache.commons.lang.builder.ToStringStyle;
-import org.sonar.api.batch.fs.InputFile;
-
-import javax.annotation.Nullable;
 
 public abstract class DefaultStorable {
 
-  protected transient final SensorStorage storage;
+  protected final transient SensorStorage storage;
   private transient boolean saved = false;
 
   public DefaultStorable() {
@@ -53,9 +51,4 @@ public abstract class DefaultStorable {
     return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }
 
-  protected void validateLineArgument(InputFile inputFile, int line, String label) {
-    Preconditions.checkArgument(line > 0 && line <= inputFile.lines(), "Invalid " + label + ": " + line + ". File " + inputFile + " has " + inputFile.lines()
-      + " lines.");
-  }
-
 }
index e80a5627c41df9df45be126589e5c496278fc85b..32932a71cd174b7443ca24ff522f2ae4a8dae2bb 100644 (file)
@@ -29,13 +29,11 @@ import java.util.Set;
 import javax.annotation.Nonnull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.fs.FileSystem;
 import org.sonar.api.batch.fs.InputComponent;
 import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextRange;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.rule.ActiveRules;
 import org.sonar.api.batch.sensor.coverage.CoverageType;
 import org.sonar.api.batch.sensor.coverage.internal.DefaultCoverage;
 import org.sonar.api.batch.sensor.cpd.internal.DefaultCpdTokens;
@@ -75,7 +73,7 @@ public class DefaultSensorStorage implements SensorStorage {
     // Computed by LinesSensor
     CoreMetrics.LINES);
 
-  private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.<String>asList(
+  private static final List<String> DEPRECATED_METRICS_KEYS = Arrays.asList(
     CoreMetrics.DEPENDENCY_MATRIX_KEY,
     CoreMetrics.DIRECTORY_CYCLES_KEY,
     CoreMetrics.DIRECTORY_EDGES_WEIGHT_KEY,
@@ -99,7 +97,7 @@ public class DefaultSensorStorage implements SensorStorage {
   private final Settings settings;
 
   public DefaultSensorStorage(MetricFinder metricFinder, ModuleIssues moduleIssues,
-    Settings settings, FileSystem fs, ActiveRules activeRules,
+    Settings settings,
     CoverageExclusions coverageExclusions, BatchComponentCache componentCache, ReportPublisher reportPublisher, MeasureCache measureCache, SonarCpdBlockIndex index) {
     this.metricFinder = metricFinder;
     this.moduleIssues = moduleIssues;
index a1c406e2adc458417303c68e729ea469b3abd895..76afdb236610a47fbb47e79538edd6c5edef42fa 100644 (file)
@@ -26,12 +26,9 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.TemporaryFolder;
 import org.mockito.ArgumentCaptor;
 import org.sonar.api.batch.fs.InputFile;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputModule;
 import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.batch.rule.ActiveRules;
-import org.sonar.api.batch.rule.internal.ActiveRulesBuilder;
 import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure;
 import org.sonar.api.config.Settings;
 import org.sonar.api.measures.CoreMetrics;
@@ -60,9 +57,7 @@ public class DefaultSensorStorageTest {
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
-  private ActiveRules activeRules;
-  private DefaultFileSystem fs;
-  private DefaultSensorStorage sensorStorage;
+  private DefaultSensorStorage underTest;
   private Settings settings;
   private ModuleIssues moduleIssues;
   private Project project;
@@ -71,9 +66,7 @@ public class DefaultSensorStorageTest {
   private BatchComponentCache resourceCache;
 
   @Before
-  public void prepare() throws Exception {
-    activeRules = new ActiveRulesBuilder().build();
-    fs = new DefaultFileSystem(temp.newFolder().toPath());
+  public void prepare() {
     MetricFinder metricFinder = mock(MetricFinder.class);
     when(metricFinder.<Integer>findByKey(CoreMetrics.NCLOC_KEY)).thenReturn(CoreMetrics.NCLOC);
     when(metricFinder.<String>findByKey(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY)).thenReturn(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION);
@@ -84,18 +77,18 @@ public class DefaultSensorStorageTest {
     CoverageExclusions coverageExclusions = mock(CoverageExclusions.class);
     when(coverageExclusions.accept(any(Resource.class), any(Measure.class))).thenReturn(true);
     resourceCache = new BatchComponentCache();
-    sensorStorage = new DefaultSensorStorage(metricFinder,
-      moduleIssues, settings, fs, activeRules, coverageExclusions, resourceCache, mock(ReportPublisher.class), measureCache, mock(SonarCpdBlockIndex.class));
+    underTest = new DefaultSensorStorage(metricFinder,
+      moduleIssues, settings, coverageExclusions, resourceCache, mock(ReportPublisher.class), measureCache, mock(SonarCpdBlockIndex.class));
   }
 
   @Test
-  public void shouldFailIfUnknowMetric() {
+  public void shouldFailIfUnknownMetric() {
     InputFile file = new DefaultInputFile("foo", "src/Foo.php");
 
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("Unknow metric with key: lines");
 
-    sensorStorage.store(new DefaultMeasure()
+    underTest.store(new DefaultMeasure()
       .on(file)
       .forMetric(CoreMetrics.LINES)
       .withValue(10));
@@ -109,7 +102,7 @@ public class DefaultSensorStorageTest {
     Resource sonarFile = File.create("src/Foo.php").setEffectiveKey("foo:src/Foo.php");
     resourceCache.add(sonarFile, null).setInputComponent(file);
     when(measureCache.put(eq(sonarFile), argumentCaptor.capture())).thenReturn(null);
-    sensorStorage.store(new DefaultMeasure()
+    underTest.store(new DefaultMeasure()
       .on(file)
       .forMetric(CoreMetrics.NCLOC)
       .withValue(10));
@@ -127,7 +120,7 @@ public class DefaultSensorStorageTest {
     ArgumentCaptor<org.sonar.api.measures.Measure> argumentCaptor = ArgumentCaptor.forClass(org.sonar.api.measures.Measure.class);
     when(measureCache.put(eq(project), argumentCaptor.capture())).thenReturn(null);
 
-    sensorStorage.store(new DefaultMeasure()
+    underTest.store(new DefaultMeasure()
       .on(module)
       .forMetric(CoreMetrics.NCLOC)
       .withValue(10));