]> source.dussan.org Git - sonarqube.git/commitdiff
Improve quality
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 12 Jul 2016 12:27:15 +0000 (14:27 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 12 Jul 2016 12:27:19 +0000 (14:27 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java

index 0daadad90df6487b77011d8589b93477b50ecd5b..bcd9941d3872fe59dff7ffa074aa36b1e3a96126 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.api.batch.bootstrap;
 
+@FunctionalInterface
 public interface ProjectKey {
   String get();
 }
index 3b9f62a4856ed64a50e4f08a64feb0cc7095f9b5..cb67b294f5444d4f05576dabb45ff8f942c432eb 100644 (file)
@@ -31,8 +31,10 @@ import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.TextPointer;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DefaultTextPointer;
+import org.sonar.api.batch.sensor.error.NewAnalysisError;
 import org.sonar.api.batch.sensor.internal.SensorStorage;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.*;
 
 public class DefaultAnalysisErrorTest {
   private InputFile inputFile;
@@ -71,8 +73,42 @@ public class DefaultAnalysisErrorTest {
   }
 
   @Test
-  public void test_must_have_file() {
+  public void test_no_storage() {
     exception.expect(NullPointerException.class);
-    new DefaultAnalysisError(storage).save();
+    DefaultAnalysisError analysisError = new DefaultAnalysisError();
+    analysisError.onFile(inputFile).save();
+  }
+
+  @Test
+  public void test_validation() {
+    try {
+      new DefaultAnalysisError(storage).onFile(null);
+      fail("Expected exception");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+
+    NewAnalysisError error = new DefaultAnalysisError(storage).onFile(inputFile);
+    try {
+      error.onFile(inputFile);
+      fail("Expected exception");
+    } catch (IllegalStateException e) {
+      // expected
+    }
+
+    error = new DefaultAnalysisError(storage).at(textPointer);
+    try {
+      error.at(textPointer);
+      fail("Expected exception");
+    } catch (IllegalStateException e) {
+      // expected
+    }
+
+    try {
+      new DefaultAnalysisError(storage).save();
+      fail("Expected exception");
+    } catch (NullPointerException e) {
+      // expected
+    }
   }
 }
index 07b03c182570e498d2d60e0996e24b9ab17fd469..285a25d6848285aa63b07c4907216122f4f68638 100644 (file)
@@ -114,12 +114,7 @@ public class CpdExecutor {
     List<CloneGroup> duplications;
     Future<List<CloneGroup>> futureResult = null;
     try {
-      futureResult = executorService.submit(new Callable<List<CloneGroup>>() {
-        @Override
-        public List<CloneGroup> call() throws Exception {
-          return SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks);
-        }
-      });
+      futureResult = executorService.submit(() -> SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks));
       duplications = futureResult.get(TIMEOUT, TimeUnit.SECONDS);
     } catch (TimeoutException e) {
       LOG.warn("Timeout during detection of duplications for " + inputFile.absolutePath());
index c2d14632cfa0368a15fb54a1d5016cb1358ff64b..1640ce17ff0a96f383cc6f602cd3c4d8619d8deb 100644 (file)
@@ -53,11 +53,6 @@ public class WorkDirectoryCleaner {
   }
 
   private DirectoryStream<Path> list() throws IOException {
-    return Files.newDirectoryStream(workDir, new DirectoryStream.Filter<Path>() {
-      @Override
-      public boolean accept(Path entry) throws IOException {
-        return !DirectoryLock.LOCK_FILE_NAME.equals(entry.getFileName().toString());
-      }
-    });
+    return Files.newDirectoryStream(workDir, entry -> !DirectoryLock.LOCK_FILE_NAME.equals(entry.getFileName().toString()));
   }
 }