Skip to content

Commit

Permalink
Improve quality
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmeneses committed Jul 12, 2016
1 parent 7bea09f commit 6bffda8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
Expand Up @@ -19,6 +19,7 @@
*/
package org.sonar.api.batch.bootstrap;

@FunctionalInterface
public interface ProjectKey {
String get();
}
Expand Up @@ -31,8 +31,10 @@
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;
Expand Down Expand Up @@ -71,8 +73,42 @@ public void test_save() {
}

@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
}
}
}
Expand Up @@ -114,12 +114,7 @@ private void runCpdAnalysis(String resource, final Collection<Block> fileBlocks)
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());
Expand Down
Expand Up @@ -53,11 +53,6 @@ public void execute() {
}

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()));
}
}

0 comments on commit 6bffda8

Please sign in to comment.