Search in sources :

Example 81 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.

the class SonarComponentsTest method knows_if_quickfixes_can_be_advertised.

@Test
void knows_if_quickfixes_can_be_advertised() {
    SensorContextTester context = SensorContextTester.create(new File(""));
    SonarComponents sonarComponents = new SonarComponents(null, null, null, null, null);
    sonarComponents.setSensorContext(context);
    assertTrue(sonarComponents.isSetQuickFixAvailableCompatible());
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Test(org.junit.jupiter.api.Test) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 82 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.

the class SyntaxHighlighterVisitorTest method parse_error.

@Test
void parse_error() throws Exception {
    SensorContextTester spy = spy(context);
    File file = temp.newFile().getAbsoluteFile();
    Files.asCharSink(file, StandardCharsets.UTF_8).write("ParseError");
    scan(TestUtils.inputFile(file));
    verify(spy, never()).newHighlighting();
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 83 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.

the class JavaFrontendTest method test_scan_logs_when_caching_is_disabled_when_sonar_components_is_null.

@Test
void test_scan_logs_when_caching_is_disabled_when_sonar_components_is_null() {
    File baseDir = temp.getRoot().getAbsoluteFile();
    SensorContextTester sensorContextTester = SensorContextTester.create(baseDir);
    sensorContextTester.setSettings(new MapSettings());
    JavaFrontend frontend = new JavaFrontend(new JavaVersionImpl(), null, null, mock(JavaResourceLocator.class), mainCodeIssueScannerAndFilter);
    frontend.scan(Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    List<String> logs = logTester.getLogs(LoggerLevel.INFO).stream().map(LogAndArguments::getFormattedMsg).collect(Collectors.toList());
    assertThat(logs).isNotEmpty().containsExactly("Server-side caching is not enabled. The Java analyzer will not try to leverage data from a previous analysis.", "No \"Main\" source files to scan.", "No \"Test\" source files to scan.", "No \"Generated\" source files to scan.");
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) JavaVersionImpl(org.sonar.java.model.JavaVersionImpl) JavaResourceLocator(org.sonar.plugins.java.api.JavaResourceLocator) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) Test(org.junit.jupiter.api.Test) ClasspathForTest(org.sonar.java.classpath.ClasspathForTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 84 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-python by SonarSource.

the class BanditSensorTest method test_descriptor.

@Test
public void test_descriptor() {
    DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();
    banditSensor.describe(sensorDescriptor);
    assertThat(sensorDescriptor.name()).isEqualTo("Import of Bandit issues");
    assertThat(sensorDescriptor.languages()).containsOnly("py");
    assertThat(sensorDescriptor.configurationPredicate()).isNotNull();
    assertNoErrorWarnDebugLogs(logTester);
    Path baseDir = PROJECT_DIR.getParent();
    SensorContextTester context = SensorContextTester.create(baseDir);
    context.settings().setProperty(BANDIT_PROPERTY, "path/to/report");
    assertThat(sensorDescriptor.configurationPredicate().test(context.config())).isTrue();
    context = SensorContextTester.create(baseDir);
    context.settings().setProperty("sonar.python.bandit.reportPath", "path/to/report");
    // No support of "reportPath" property for Bandit
    assertThat(sensorDescriptor.configurationPredicate().test(context.config())).isFalse();
}
Also used : Path(java.nio.file.Path) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Example 85 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-python by SonarSource.

the class PylintSensorTest method test_descriptor.

@Test
public void test_descriptor() {
    DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor();
    pylintSensor.describe(sensorDescriptor);
    assertThat(sensorDescriptor.name()).isEqualTo("Import of Pylint issues");
    assertThat(sensorDescriptor.languages()).containsOnly("py");
    assertThat(sensorDescriptor.configurationPredicate()).isNotNull();
    assertNoErrorWarnLogs(logTester);
    Path baseDir = PROJECT_DIR.getParent();
    SensorContextTester context = SensorContextTester.create(baseDir);
    context.settings().setProperty(DEFAULT_PROPERTY, "path/to/report");
    assertThat(sensorDescriptor.configurationPredicate().test(context.config())).isTrue();
    context = SensorContextTester.create(baseDir);
    context.settings().setProperty(LEGACY_PROPERTY, "path/to/report");
    // Support of legacy "reportPath" property for Pylint
    assertThat(sensorDescriptor.configurationPredicate().test(context.config())).isTrue();
    context = SensorContextTester.create(baseDir);
    context.settings().setProperty("random.key", "path/to/report");
    assertThat(sensorDescriptor.configurationPredicate().test(context.config())).isFalse();
}
Also used : Path(java.nio.file.Path) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultSensorDescriptor(org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor) Test(org.junit.Test)

Aggregations

SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)224 File (java.io.File)96 Test (org.junit.jupiter.api.Test)94 InputFile (org.sonar.api.batch.fs.InputFile)75 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)63 MapSettings (org.sonar.api.config.internal.MapSettings)60 Test (org.junit.Test)59 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)49 Test (org.testng.annotations.Test)42 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)40 OpenEdgePluginTest (org.sonar.plugins.openedge.OpenEdgePluginTest)37 Path (java.nio.file.Path)35 OpenEdgeSettings (org.sonar.plugins.openedge.foundation.OpenEdgeSettings)30 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)25 SonarComponents (org.sonar.java.SonarComponents)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 GeneratedFile (org.sonar.java.model.GeneratedFile)18 ArrayList (java.util.ArrayList)15 ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14