Search in sources :

Example 1 with AnalysisError

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);
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) AnalysisError(org.sonar.java.AnalysisError) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)1 AnalysisError (org.sonar.java.AnalysisError)1