use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_no_issues_but_xml_file_still_published.
@Test
public void test_no_issues_but_xml_file_still_published() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven2/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven2/pom.xml");
DefaultInputFile inputFile = new TestInputFileBuilder("", "pom.xml").setModuleBaseDir(fs.baseDirPath()).setPublish(false).build();
fs.add(inputFile);
SonarComponents sonarComponents = createSonarComponentsMock(fs, file);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
assertThat(inputFile.isPublished()).isFalse();
sensor.execute(context);
assertThat(inputFile.isPublished()).isTrue();
verify(sonarComponents, never()).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class SurefireJavaParserTest method should_log_missing_resource_with_debug_level.
@Test
public void should_log_missing_resource_with_debug_level() throws Exception {
SensorContextTester context = mockContext();
parser = new SurefireJavaParser(mock(ResourcePerspectives.class), mock(JavaResourceLocator.class));
parser.collect(context, getDirs("resourceNotFound"), true);
assertThat(logTester.logs(LoggerLevel.WARN)).isEmpty();
assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Resource not found: org.sonar.Foo");
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class SurefireJavaParserTest method shouldAggregateReports.
@Test
public void shouldAggregateReports() throws URISyntaxException {
SensorContextTester context = mockContext();
parser.collect(context, getDirs("multipleReports"), true);
assertThat(context.measures(":ch.hortis.sonar.mvn.mc.MetricsCollectorRegistryTest")).hasSize(5);
assertThat(context.measures(":ch.hortis.sonar.mvn.mc.CloverCollectorTest")).hasSize(5);
assertThat(context.measures(":ch.hortis.sonar.mvn.mc.CheckstyleCollectorTest")).hasSize(5);
assertThat(context.measures(":ch.hortis.sonar.mvn.SonarMojoTest")).hasSize(5);
assertThat(context.measures(":ch.hortis.sonar.mvn.mc.JDependsCollectorTest")).hasSize(5);
assertThat(context.measures(":ch.hortis.sonar.mvn.mc.JavaNCSSCollectorTest")).hasSize(5);
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class SurefireJavaParserTest method shouldMergeNestedInnerClasses.
@Test
public void shouldMergeNestedInnerClasses() throws URISyntaxException {
SensorContextTester context = mockContext();
parser.collect(context, getDirs("nestedInnerClasses"), true);
assertThat(context.measure(":org.sonar.plugins.surefire.NestedInnerTest", CoreMetrics.TESTS).value()).isEqualTo(3);
}
use of org.sonar.api.batch.sensor.internal.SensorContextTester in project sonar-java by SonarSource.
the class SyntaxHighlighterVisitorTest method parse_error.
@Test
public void parse_error() throws Exception {
SensorContextTester spy = spy(context);
File file = temp.newFile().getAbsoluteFile();
Files.write("ParseError", file, StandardCharsets.UTF_8);
fs.add(new TestInputFileBuilder("", file.getName()).build());
scan(file);
verify(spy, never()).newHighlighting();
}
Aggregations