use of org.sonar.java.AnalysisError in project sonar-java by SonarSource.
the class JavaSquidSensorTest method verify_analysis_errors_are_collected_on_parse_error.
@Test
public void verify_analysis_errors_are_collected_on_parse_error() throws Exception {
SensorContextTester context = createParseErrorContext();
context.settings().setProperty(SonarComponents.COLLECT_ANALYSIS_ERRORS_KEY, true);
executeJavaSquidSensor(context);
String feedback = context.<String>measure("projectKey", "sonarjava_feedback").value();
Collection<AnalysisError> analysisErrors = new Gson().fromJson(feedback, new TypeToken<Collection<AnalysisError>>() {
}.getType());
assertThat(analysisErrors).hasSize(1);
AnalysisError analysisError = analysisErrors.iterator().next();
assertThat(analysisError.getMessage()).startsWith("Parse error at line 6 column 1:");
assertThat(analysisError.getCause()).startsWith("com.sonar.sslr.api.RecognitionException: Parse error at line 6 column 1:");
assertThat(analysisError.getFilename()).endsWith("ParseError.java");
assertThat(analysisError.getKind()).isEqualTo(AnalysisError.Kind.PARSE_ERROR);
}
Aggregations