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());
}
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();
}
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.");
}
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();
}
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();
}
Aggregations