use of com.sonar.sslr.impl.LexerException in project sonar-java by SonarSource.
the class SonarComponentsTest method add_issue_or_parse_error.
@Test
public void add_issue_or_parse_error() throws Exception {
JavaCheck expectedCheck = new CustomCheck();
CheckRegistrar expectedRegistrar = getRegistrar(expectedCheck);
SensorContextTester context = SensorContextTester.create(new File(""));
DefaultFileSystem fileSystem = context.fileSystem();
File file = new File("file.java");
TestInputFileBuilder inputFile = new TestInputFileBuilder("", "file.java");
inputFile.setLines(45);
int[] linesOffset = new int[45];
linesOffset[35] = 12;
linesOffset[42] = 1;
inputFile.setOriginalLineOffsets(linesOffset);
inputFile.setLastValidOffset(420);
fileSystem.add(inputFile.build());
when(this.checks.ruleKey(any(JavaCheck.class))).thenReturn(mock(RuleKey.class));
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fileSystem, null, null, checkFactory, new CheckRegistrar[] { expectedRegistrar });
sonarComponents.setSensorContext(context);
sonarComponents.addIssue(file, expectedCheck, -5, "message on wrong line", null);
sonarComponents.addIssue(file, expectedCheck, 42, "message on line", 1);
sonarComponents.addIssue(new File("."), expectedCheck, 42, "message on line", 1);
sonarComponents.addIssue(new File("unknown_file"), expectedCheck, 42, "message on line", 1);
sonarComponents.reportIssue(new AnalyzerMessage(expectedCheck, file, 35, "other message", 0));
assertThat(context.allIssues()).hasSize(3);
RecognitionException parseError = new RecognitionException(new LexerException("parse error"));
context.setRuntime(SonarRuntimeImpl.forSonarLint(V6_7));
assertThat(sonarComponents.reportAnalysisError(parseError, file)).isTrue();
context.setRuntime(SonarRuntimeImpl.forSonarQube(V6_7, SonarQubeSide.SCANNER));
assertThat(sonarComponents.reportAnalysisError(parseError, file)).isFalse();
}
Aggregations