use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class IssueExclusionsRegexpScannerTests method init.
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
blockPatterns = Arrays.asList(new DoubleRegexpMatcher(Pattern.compile("// SONAR-OFF"), Pattern.compile("// SONAR-ON")), new DoubleRegexpMatcher(Pattern.compile("// FOO-OFF"), Pattern.compile("// FOO-ON")));
allFilePatterns = Collections.singletonList(Pattern.compile("@SONAR-IGNORE-ALL"));
javaFile = new SonarLintInputFile(new OnDiskTestClientInputFile(Paths.get("src/Foo.java"), "src/Foo.java", false, StandardCharsets.UTF_8), f -> mock(Metadata.class));
regexpScanner = new IssueExclusionsRegexpScanner(javaFile, allFilePatterns, blockPatterns);
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class ModuleInputFileBuilderTests method testCreate_lazy_error.
@Test
void testCreate_lazy_error() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn(Language.JAVA);
ClientInputFile file = new OnDiskTestClientInputFile(Paths.get("INVALID"), "INVALID", true, StandardCharsets.ISO_8859_1);
var builder = new ModuleInputFileBuilder(langDetection, metadata);
var slFile = builder.create(file);
// Call any method that will trigger metadata initialization
var thrown = assertThrows(IllegalStateException.class, () -> slFile.selectLine(1));
assertThat(thrown).hasMessageStartingWith("Failed to open a stream on file");
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class ModuleInputFileBuilderTests method testCreateWithLanguageSet.
@Test
void testCreateWithLanguageSet() throws IOException {
var path = tempDir.resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new OnDiskTestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1, Language.CPP);
var builder = new ModuleInputFileBuilder(langDetection, metadata);
var inputFile = builder.create(file);
assertThat(inputFile.language()).isEqualTo("cpp");
verifyNoInteractions(langDetection);
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class ModuleInputFileBuilderTests method testCreate.
@Test
void testCreate() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn(Language.JAVA);
var path = tempDir.resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new OnDiskTestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1);
var builder = new ModuleInputFileBuilder(langDetection, metadata);
var inputFile = builder.create(file);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.file()).isEqualTo(path.toFile());
assertThat(inputFile.absolutePath()).isEqualTo(FileUtils.toSonarQubePath(path.toString()));
assertThat(inputFile.language()).isEqualTo("java");
assertThat(inputFile.key()).isEqualTo(path.toUri().toString());
assertThat(inputFile.lines()).isEqualTo(1);
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTests method testCreate_lazy_error.
@Test
void testCreate_lazy_error() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn(Language.JAVA);
ClientInputFile file = new OnDiskTestClientInputFile(Paths.get("INVALID"), "INVALID", true, StandardCharsets.ISO_8859_1);
var builder = new InputFileBuilder(langDetection, metadata, issueExclusionsLoader);
var slFile = builder.create(file);
// Call any method that will trigger metadata initialization
var thrown = assertThrows(IllegalStateException.class, () -> slFile.selectLine(1));
assertThat(thrown).hasMessageStartingWith("Failed to open a stream on file");
}
Aggregations