use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class ExternalIssueImporterTest method prepare.
@Before
public void prepare() throws Exception {
File baseDir = temp.newFolder();
context = SensorContextTester.create(baseDir);
sourceFile = new TestInputFileBuilder("foo", "src/Foo.java").setModuleBaseDir(baseDir.toPath()).initMetadata("the first line\nthe second line").setCharset(UTF_8).setLanguage("java").build();
context.fileSystem().add(sourceFile);
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class FileMetadataTest method ignore_whitespace_when_computing_line_hashes.
@Test
public void ignore_whitespace_when_computing_line_hashes() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", StandardCharsets.UTF_8, true);
DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName()).setModuleBaseDir(tempFile.getParentFile().toPath()).setCharset(StandardCharsets.UTF_8).build();
FileMetadata.computeLineHashesForIssueTracking(f, new FileMetadata.LineHashConsumer() {
@Override
public void consume(int lineIdx, @Nullable byte[] hash) {
switch(lineIdx) {
case 1:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("foo"));
break;
case 2:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("bar"));
break;
case 3:
assertThat(Hex.encodeHexString(hash)).isEqualTo(md5Hex("baz"));
break;
default:
fail("Invalid line");
}
}
});
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class FileMetadataTest method dont_fail_on_empty_file.
@Test
public void dont_fail_on_empty_file() throws Exception {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "", StandardCharsets.UTF_8, true);
DefaultInputFile f = new TestInputFileBuilder("foo", tempFile.getName()).setModuleBaseDir(tempFile.getParentFile().toPath()).setCharset(StandardCharsets.UTF_8).build();
FileMetadata.computeLineHashesForIssueTracking(f, new FileMetadata.LineHashConsumer() {
@Override
public void consume(int lineIdx, @Nullable byte[] hash) {
switch(lineIdx) {
case 1:
assertThat(hash).isNull();
break;
default:
fail("Invalid line");
}
}
});
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class DefaultFileSystemTest method inputFiles_using_optimized_predicates.
@Test
public void inputFiles_using_optimized_predicates() {
fs.add(new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build());
fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build());
assertThat(fs.inputFiles(fs.predicates().hasFilename("Foo.php"))).hasSize(1);
assertThat(fs.inputFiles(fs.predicates().hasFilename("unknown"))).isEmpty();
assertThat(fs.inputFiles(fs.predicates().hasExtension("java"))).hasSize(2);
assertThat(fs.inputFiles(fs.predicates().hasExtension("unknown"))).isEmpty();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class DefaultFileSystemTest method hasFiles_using_optimized_predicates.
@Test
public void hasFiles_using_optimized_predicates() {
fs.add(new TestInputFileBuilder("foo", "src/Foo.php").setLanguage("php").build());
fs.add(new TestInputFileBuilder("foo", "src/Bar.java").setLanguage("java").build());
fs.add(new TestInputFileBuilder("foo", "src/Baz.java").setLanguage("java").build());
assertThat(fs.hasFiles(fs.predicates().hasFilename("Foo.php"))).isTrue();
assertThat(fs.hasFiles(fs.predicates().hasFilename("unknown"))).isFalse();
assertThat(fs.hasFiles(fs.predicates().hasExtension("java"))).isTrue();
assertThat(fs.hasFiles(fs.predicates().hasExtension("unknown"))).isFalse();
}
Aggregations