aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-12 14:27:15 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-07-12 14:27:19 +0200
commit6bffda848ed609d1761de69db7f7360c02172719 (patch)
tree2ea1c766a92951a9068ed50813bde3ccbb0ab7d4
parent7bea09f6eb442441908de2df48b0ed7dd75e001f (diff)
downloadsonarqube-6bffda848ed609d1761de69db7f7360c02172719.tar.gz
sonarqube-6bffda848ed609d1761de69db7f7360c02172719.zip
Improve quality
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java1
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java40
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java7
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java7
4 files changed, 41 insertions, 14 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
index 0daadad90df..bcd9941d387 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectKey.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.batch.bootstrap;
+@FunctionalInterface
public interface ProjectKey {
String get();
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java
index 3b9f62a4856..cb67b294f54 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/sensor/error/internal/DefaultAnalysisErrorTest.java
@@ -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
+ }
}
}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
index 07b03c18257..285a25d6848 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/cpd/CpdExecutor.java
@@ -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());
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java
index c2d14632cfa..1640ce17ff0 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/WorkDirectoryCleaner.java
@@ -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()));
}
}