Search in sources :

Example 1 with MapSettings

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

the class SensorOptimizerTest method prepare.

@Before
public void prepare() throws Exception {
    fs = new DefaultFileSystem(temp.newFolder().toPath());
    settings = new MapSettings();
    optimizer = new SensorOptimizer(fs, new ActiveRulesBuilder().build(), settings.asConfig());
}
Also used : ActiveRulesBuilder(org.sonar.api.batch.rule.internal.ActiveRulesBuilder) MapSettings(org.sonar.api.config.internal.MapSettings) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Before(org.junit.Before)

Example 2 with MapSettings

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

the class DefaultServerTest method coverageUnusedMethods.

@Test
public void coverageUnusedMethods() {
    SonarRuntime runtime = mock(SonarRuntime.class);
    when(runtime.getApiVersion()).thenReturn(Version.create(2, 2));
    DefaultServer metadata = new DefaultServer(new MapSettings(), runtime);
    assertThat(metadata.getStartedAt()).isNull();
    assertThat(metadata.getRootDir()).isNull();
    assertThat(metadata.getContextPath()).isNull();
    assertThat(metadata.isSecured()).isFalse();
    assertThat(metadata.isDev()).isFalse();
    assertThat(metadata.getPublicRootUrl()).isNull();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) SonarRuntime(org.sonar.api.SonarRuntime) Test(org.junit.Test)

Example 3 with MapSettings

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

the class JavaSquidSensorTest method testIssueCreation.

private void testIssueCreation(InputFile.Type onType, int expectedIssues) throws IOException {
    MapSettings settings = new MapSettings();
    NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
    SensorContextTester context = createContext(onType).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
    DefaultFileSystem fs = context.fileSystem();
    SonarComponents sonarComponents = createSonarComponentsMock(context);
    DefaultJavaResourceLocator javaResourceLocator = new DefaultJavaResourceLocator(fs, new JavaClasspath(settings.asConfig(), fs));
    PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
    JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, settings.asConfig(), noSonarFilter, postAnalysisIssueFilter);
    jss.execute(context);
    verify(noSonarFilter, times(1)).noSonarInFile(fs.inputFiles().iterator().next(), Sets.newHashSet(96));
    verify(sonarComponents, times(expectedIssues)).reportIssue(any(AnalyzerMessage.class));
    settings.setProperty(Java.SOURCE_VERSION, "wrongFormat");
    jss.execute(context);
    settings.setProperty(Java.SOURCE_VERSION, "1.7");
    jss.execute(context);
}
Also used : SonarComponents(org.sonar.java.SonarComponents) JavaClasspath(org.sonar.java.JavaClasspath) MapSettings(org.sonar.api.config.internal.MapSettings) NoSonarFilter(org.sonar.api.issue.NoSonarFilter) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) PostAnalysisIssueFilter(org.sonar.java.filters.PostAnalysisIssueFilter) DefaultJavaResourceLocator(org.sonar.java.DefaultJavaResourceLocator) AnalyzerMessage(org.sonar.java.AnalyzerMessage) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem)

Example 4 with MapSettings

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

the class SurefireUtilsTest method return_default_value_if_property_unset.

@Test
public void return_default_value_if_property_unset() throws Exception {
    MapSettings settings = new MapSettings();
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(1);
    File directory = directories.get(0);
    assertThat(directory.getCanonicalPath()).endsWith("target" + File.separator + "surefire-reports");
    assertThat(directory.exists()).isFalse();
    assertThat(directory.isDirectory()).isFalse();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 5 with MapSettings

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

the class SurefireUtilsTest method should_get_report_paths_from_property.

@Test
public void should_get_report_paths_from_property() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(2);
    File directory1 = directories.get(0);
    assertThat(directory1.exists()).isTrue();
    assertThat(directory1.isDirectory()).isTrue();
    File directory2 = directories.get(1);
    assertThat(directory2.exists()).isTrue();
    assertThat(directory2.isDirectory()).isTrue();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.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