Search in sources :

Example 1 with NewAnalysisError

use of org.sonar.api.batch.sensor.error.NewAnalysisError 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)

Example 2 with NewAnalysisError

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

the class DefaultAnalysisErrorTest method test_validation.

@Test
public void test_validation() {
    try {
        new DefaultAnalysisError(storage).onFile(null);
        fail("Expected exception");
    } catch (IllegalArgumentException e) {
    // expected
    }
    NewAnalysisError error = new DefaultAnalysisError(storage).onFile(inputFile);
    try {
        error.onFile(inputFile);
        fail("Expected exception");
    } catch (IllegalStateException e) {
    // expected
    }
    error = new DefaultAnalysisError(storage).at(textPointer);
    try {
        error.at(textPointer);
        fail("Expected exception");
    } catch (IllegalStateException e) {
    // expected
    }
    try {
        new DefaultAnalysisError(storage).save();
        fail("Expected exception");
    } catch (NullPointerException e) {
    // expected
    }
}
Also used : NewAnalysisError(org.sonar.api.batch.sensor.error.NewAnalysisError) Test(org.junit.Test)

Aggregations

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