Search in sources :

Example 21 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class SurefireSensorTest method shouldNotFailIfReportsNotFound.

@Test
public void shouldNotFailIfReportsNotFound() {
    MapSettings settings = new MapSettings();
    settings.setProperty(SurefireUtils.SUREFIRE_REPORTS_PATH_PROPERTY, "unknown");
    SurefireSensor surefireSensor = new SurefireSensor(mock(SurefireJavaParser.class), settings.asConfig(), fs, pathResolver);
    surefireSensor.execute(mock(SensorContext.class));
}
Also used : SensorContext(org.sonar.api.batch.sensor.SensorContext) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 22 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class SurefireSensorTest method before.

@Before
public void before() {
    fs = new DefaultFileSystem(new File("src/test/resources"));
    DefaultInputFile javaFile = new TestInputFileBuilder("", "src/org/foo/java").setLanguage("java").build();
    fs.add(javaFile);
    perspectives = mock(ResourcePerspectives.class);
    javaResourceLocator = mock(JavaResourceLocator.class);
    when(javaResourceLocator.findResourceByClassName(anyString())).thenAnswer(invocation -> resource((String) invocation.getArguments()[0]));
    surefireSensor = new SurefireSensor(new SurefireJavaParser(perspectives, javaResourceLocator), new MapSettings().asConfig(), fs, pathResolver);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ResourcePerspectives(org.sonar.api.component.ResourcePerspectives) JavaResourceLocator(org.sonar.plugins.java.api.JavaResourceLocator) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 23 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JavaTest method should_return_java_file_suffixes.

@Test
public void should_return_java_file_suffixes() {
    MapSettings settings = new MapSettings();
    Java language = new Java(settings.asConfig());
    assertThat(language.getFileSuffixes()).containsOnly(".java", ".jav");
    settings.setProperty(Java.FILE_SUFFIXES_KEY, "");
    assertThat(language.getFileSuffixes()).containsOnly(".java", ".jav");
    settings.setProperty(Java.FILE_SUFFIXES_KEY, ".bar, .foo");
    assertThat(language.getFileSuffixes()).containsOnly(".bar", ".foo");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 24 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-go by SonarSource.

the class GoCoverageReportTest method upload_reports.

@Test
void upload_reports() throws IOException {
    Path baseDir = COVERAGE_DIR.toAbsolutePath();
    SensorContextTester context = SensorContextTester.create(baseDir);
    context.setSettings(new MapSettings());
    context.settings().setProperty("sonar.go.coverage.reportPaths", "coverage.relative.out");
    Path goFilePath = baseDir.resolve("cover.go");
    String content = new String(Files.readAllBytes(goFilePath), UTF_8);
    context.fileSystem().add(TestInputFileBuilder.create("moduleKey", baseDir.toFile(), goFilePath.toFile()).setLanguage("go").setType(InputFile.Type.MAIN).initMetadata(content).build());
    GoContext goContext = new GoContext(File.separatorChar, COVERAGE_DIR.toString());
    GoCoverageReport.saveCoverageReports(context, goContext);
    String fileKey = "moduleKey:cover.go";
    assertThat(context.lineHits(fileKey, 3)).isNull();
    assertThat(context.lineHits(fileKey, 4)).isEqualTo(1);
    assertThat(context.lineHits(fileKey, 5)).isEqualTo(2);
    assertThat(context.conditions(fileKey, 5)).isNull();
    assertThat(context.coveredConditions(fileKey, 5)).isNull();
    assertThat(context.lineHits(fileKey, 6)).isEqualTo(0);
    assertThat(context.lineHits(fileKey, 7)).isEqualTo(0);
    assertThat(context.lineHits(fileKey, 8)).isNull();
}
Also used : Path(java.nio.file.Path) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) GoContext(org.sonar.go.plugin.GoCoverageReport.GoContext) Test(org.junit.jupiter.api.Test)

Aggregations

MapSettings (org.sonar.api.config.internal.MapSettings)24 Test (org.junit.Test)11 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)11 File (java.io.File)9 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)5 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 SonarComponents (org.sonar.java.SonarComponents)4 JavaClasspath (org.sonar.java.JavaClasspath)3 Path (java.nio.file.Path)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SonarRuntime (org.sonar.api.SonarRuntime)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)2