use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTest method testCreateError.
@Test
public void testCreateError() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn("java");
ClientInputFile file = new TestClientInputFile(Paths.get("INVALID"), "INVALID", true, StandardCharsets.ISO_8859_1);
InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
exception.expect(IllegalStateException.class);
exception.expectMessage("Failed to open a stream on file");
builder.create(file);
}
use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.
the class LoggedErrorHandlerTest method setUp.
@Before
public void setUp() {
file1 = new TestClientInputFile(path1, "my/file1", false, StandardCharsets.UTF_8);
file2 = new TestClientInputFile(path2, "my/file2", false, StandardCharsets.UTF_8);
handler = new LoggedErrorHandler(Arrays.asList(file1, file2));
}
use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method useRelativePathToEvaluatePathPatterns.
// SLCORE-162
@Test
public void useRelativePathToEvaluatePathPatterns() throws Exception {
// Temporary file doesn't have the correct file suffix
final File file = new File(baseDir, "foo.tmp");
FileUtils.write(file, "def my_function(name):\n" + " print \"Hello\"\n" + " print \"world!\" # NOSONAR\n" + "\n", StandardCharsets.UTF_8);
ClientInputFile inputFile = new TestClientInputFile(file.toPath(), "foo.py", false, StandardCharsets.UTF_8, null);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("python:PrintStatementUsage", 2, inputFile.getPath()));
}
use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest, Charset encoding, @Nullable String language) throws IOException {
final File file = new File(baseDir, relativePath);
FileUtils.write(file, content, encoding);
ClientInputFile inputFile = new TestClientInputFile(file.toPath(), relativePath, isTest, encoding, language);
return inputFile;
}
use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.
the class InputFileBuilderTest method testCreate.
@Test
public void testCreate() throws IOException {
when(langDetection.language(any(InputFile.class))).thenReturn("java");
Path path = temp.getRoot().toPath().resolve("file");
Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
ClientInputFile file = new TestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1);
InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
SonarLintInputFile inputFile = builder.create(file);
assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
assertThat(inputFile.file()).isEqualTo(path.toFile());
assertThat(inputFile.absolutePath()).isEqualTo(toSonarQubePath(path.toString()));
assertThat(inputFile.language()).isEqualTo("java");
assertThat(inputFile.key()).isEqualTo(toSonarQubePath(path.toAbsolutePath().toString()));
assertThat(inputFile.lines()).isEqualTo(1);
assertThat(builder.langDetection()).isEqualTo(langDetection);
}
Aggregations