use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTests 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 InputFileBuilder(langDetection, metadata, issueExclusionsLoader);
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);
assertThat(builder.langDetection()).isEqualTo(langDetection);
verify(issueExclusionsLoader).createCharHandlerFor(inputFile);
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class SonarLintInputFileTests method testGetters.
@Test
void testGetters(@TempDir Path path) throws IOException {
var filePath = path.resolve("foo.php");
Files.write(filePath, "test string".getBytes(StandardCharsets.UTF_8));
ClientInputFile inputFile = new OnDiskTestClientInputFile(filePath, "file", false, StandardCharsets.UTF_8);
var file = new SonarLintInputFile(inputFile, f -> new FileMetadata().readMetadata(filePath.toFile(), StandardCharsets.UTF_8));
assertThat(file.contents()).isEqualTo("test string");
assertThat(file.charset()).isEqualByComparingTo(StandardCharsets.UTF_8);
assertThat(file.absolutePath()).isEqualTo(FileUtils.toSonarQubePath(inputFile.getPath()));
assertThat(file.file()).isEqualTo(filePath.toFile());
assertThat(file.path()).isEqualTo(filePath);
assertThat(file.getClientInputFile()).isEqualTo(inputFile);
assertThat(file.status()).isEqualTo(Status.ADDED);
assertThat(file).isEqualTo(file).isNotEqualTo(mock(SonarLintInputFile.class));
var stream = file.inputStream();
try (var reader = new BufferedReader(new InputStreamReader(stream))) {
assertThat(reader.lines().collect(Collectors.joining())).isEqualTo("test string");
}
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method stop_module_should_stop_the_module_container.
@Test
void stop_module_should_stop_the_module_container() throws Exception {
sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
sonarlint.stopModule("key").get();
assertThat(moduleContainer.getPicoContainer().getLifecycleState().isStarted()).isFalse();
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTests 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 InputFileBuilder(langDetection, metadata, issueExclusionsLoader);
var inputFile = builder.create(file);
assertThat(inputFile.language()).isEqualTo("cpp");
verifyNoInteractions(langDetection);
}
Aggregations