Search in sources :

Example 1 with AnalysisError

use of org.sonar.api.batch.sensor.error.AnalysisError in project sonarqube by SonarSource.

the class AnalysisErrorSensorTest method test.

@Test
public void test() throws IOException {
    Path baseDir = temp.newFolder().toPath().toAbsolutePath();
    createErrorFile(baseDir);
    int[] offsets = { 10, 20, 30, 40 };
    DefaultInputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setOriginalLineOffsets(offsets).setModuleBaseDir(baseDir).setLines(4).build();
    context = SensorContextTester.create(baseDir);
    context.fileSystem().add(inputFile);
    sensor.execute(context);
    assertThat(context.allAnalysisErrors()).hasSize(1);
    AnalysisError error = context.allAnalysisErrors().iterator().next();
    assertThat(error.inputFile()).isEqualTo(inputFile);
    assertThat(error.location()).isEqualTo(new DefaultTextPointer(1, 4));
    assertThat(error.message()).isEqualTo("my error");
}
Also used : Path(java.nio.file.Path) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) AnalysisError(org.sonar.api.batch.sensor.error.AnalysisError) DefaultTextPointer(org.sonar.api.batch.fs.internal.DefaultTextPointer) Test(org.junit.Test)

Example 2 with AnalysisError

use of org.sonar.api.batch.sensor.error.AnalysisError in project sonarqube by SonarSource.

the class SensorContextTesterTest method testAnalysisErrors.

@Test
public void testAnalysisErrors() {
    assertThat(tester.allAnalysisErrors()).isEmpty();
    NewAnalysisError newAnalysisError = tester.newAnalysisError();
    InputFile file = new TestInputFileBuilder("foo", "src/Foo.java").build();
    newAnalysisError.onFile(file).message("error").at(new DefaultTextPointer(5, 2)).save();
    assertThat(tester.allAnalysisErrors()).hasSize(1);
    AnalysisError analysisError = tester.allAnalysisErrors().iterator().next();
    assertThat(analysisError.inputFile()).isEqualTo(file);
    assertThat(analysisError.message()).isEqualTo("error");
    assertThat(analysisError.location()).isEqualTo(new DefaultTextPointer(5, 2));
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) NewAnalysisError(org.sonar.api.batch.sensor.error.NewAnalysisError) AnalysisError(org.sonar.api.batch.sensor.error.AnalysisError) NewAnalysisError(org.sonar.api.batch.sensor.error.NewAnalysisError) DefaultTextPointer(org.sonar.api.batch.fs.internal.DefaultTextPointer) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 DefaultTextPointer (org.sonar.api.batch.fs.internal.DefaultTextPointer)2 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)2 AnalysisError (org.sonar.api.batch.sensor.error.AnalysisError)2 Path (java.nio.file.Path)1 InputFile (org.sonar.api.batch.fs.InputFile)1 NewAnalysisError (org.sonar.api.batch.sensor.error.NewAnalysisError)1