use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class DefaultSensorStorageTest method should_skip_highlighting_on_pr_when_file_status_is_SAME.
@Test
public void should_skip_highlighting_on_pr_when_file_status_is_SAME() {
DefaultInputFile file = new TestInputFileBuilder("foo", "src/Foo.php").setContents("// comment").setStatus(InputFile.Status.SAME).build();
when(branchConfiguration.isPullRequest()).thenReturn(true);
DefaultHighlighting highlighting = new DefaultHighlighting(underTest).onFile(file).highlight(1, 0, 1, 1, TypeOfText.KEYWORD);
underTest.store(highlighting);
assertThat(reportWriter.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, file.scannerId())).isFalse();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class ModuleSensorOptimizerTest method should_optimize_on_both_type_and_language.
@Test
public void should_optimize_on_both_type_and_language() {
DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor().onlyOnLanguages("java", "php").onlyOnFileType(InputFile.Type.MAIN);
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
fs.add(new TestInputFileBuilder("foo", "tests/FooTest.java").setLanguage("java").setType(InputFile.Type.TEST).build());
fs.add(new TestInputFileBuilder("foo", "src/Foo.cbl").setLanguage("cobol").setType(InputFile.Type.MAIN).build());
assertThat(optimizer.shouldExecute(descriptor)).isFalse();
fs.add(new TestInputFileBuilder("foo", "src/Foo.java").setLanguage("java").setType(InputFile.Type.MAIN).build());
assertThat(optimizer.shouldExecute(descriptor)).isTrue();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class MetadataGeneratorTest method createInputFileWithMetadata.
private DefaultInputFile createInputFileWithMetadata(Path baseDir, String relativePath) {
DefaultInputFile inputFile = new TestInputFileBuilder("struts", relativePath).setModuleBaseDir(baseDir).build();
generator.setMetadata("module", inputFile, StandardCharsets.US_ASCII);
return inputFile;
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonarqube by SonarSource.
the class AdditionalFilePredicatesTest method key.
@Test
public void key() {
FilePredicate predicate = new AdditionalFilePredicates.KeyPredicate("struts:Action.java");
InputFile inputFile = new TestInputFileBuilder("struts", "Action.java").build();
assertThat(predicate.apply(inputFile)).isTrue();
inputFile = new TestInputFileBuilder("struts", "Filter.java").build();
assertThat(predicate.apply(inputFile)).isFalse();
}
use of org.sonar.api.batch.fs.internal.TestInputFileBuilder in project sonar-web by SonarSource.
the class HeaderCheckTest method scanWithWrongInputFile.
public static void scanWithWrongInputFile(File file, DefaultNodeVisitor visitor) {
HtmlAstScanner walker = new HtmlAstScanner(Collections.emptyList());
walker.addVisitor(visitor);
FileReader reader;
try {
reader = new FileReader(file);
} catch (Exception e) {
throw new IllegalArgumentException("unable to read file");
}
HtmlSourceCode result = new HtmlSourceCode(new TestInputFileBuilder("key", /* wrong path */
".").setLanguage(HtmlConstants.LANGUAGE_KEY).setType(InputFile.Type.MAIN).setModuleBaseDir(new File(".").toPath()).build());
walker.scan(new PageLexer().parse(reader), // won't be able to resolve the file
result);
}
Aggregations