use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.
the class JavaSquidSensorTest method createSonarComponentsMock.
private static SonarComponents createSonarComponentsMock(SensorContextTester contextTester) {
Configuration settings = new MapSettings().asConfig();
DefaultFileSystem fs = contextTester.fileSystem();
JavaTestClasspath javaTestClasspath = new JavaTestClasspath(settings, fs);
JavaClasspath javaClasspath = new JavaClasspath(settings, fs);
FileLinesContext fileLinesContext = mock(FileLinesContext.class);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
SonarComponents sonarComponents = spy(new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory));
sonarComponents.setSensorContext(contextTester);
BadMethodNameCheck check = new BadMethodNameCheck();
when(sonarComponents.checkClasses()).thenReturn(new JavaCheck[] { check });
return sonarComponents;
}
use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.
the class JavaSquidSensorTest method executeJavaSquidSensor.
private void executeJavaSquidSensor(SensorContextTester context) {
context.setRuntime(SonarRuntimeImpl.forSonarQube(Version.create(6, 7), SonarQubeSide.SCANNER));
// Mock visitor for metrics.
FileLinesContext fileLinesContext = mock(FileLinesContext.class);
FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
DefaultFileSystem fs = context.fileSystem().setWorkDir(tmp.getRoot().toPath());
JavaClasspath javaClasspath = mock(JavaClasspath.class);
JavaTestClasspath javaTestClasspath = mock(JavaTestClasspath.class);
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory);
DefaultJavaResourceLocator javaResourceLocator = mock(DefaultJavaResourceLocator.class);
NoSonarFilter noSonarFilter = mock(NoSonarFilter.class);
PostAnalysisIssueFilter postAnalysisIssueFilter = new PostAnalysisIssueFilter(fs);
JavaSquidSensor jss = new JavaSquidSensor(sonarComponents, fs, javaResourceLocator, new MapSettings().asConfig(), noSonarFilter, postAnalysisIssueFilter);
jss.execute(context);
}
use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.
the class SurefireUtilsTest method should_get_reports_path_from_deprecated_property.
@Test
public void should_get_reports_path_from_deprecated_property() {
MapSettings settings = new MapSettings();
settings.setProperty("sonar.junit.reportsPath", "target/surefire");
DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromDeprecatedProperty"));
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.exists()).isTrue();
assertThat(directory.isDirectory()).isTrue();
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.
the class CheckVerifier method sonarComponents.
static SonarComponents sonarComponents(File file) {
SensorContextTester context = SensorContextTester.create(new File("")).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
context.setSettings(new MapSettings().setProperty("sonar.java.failOnException", true));
SonarComponents sonarComponents = new SonarComponents(null, context.fileSystem(), null, null, null, null) {
@Override
public boolean reportAnalysisError(RecognitionException re, File file) {
return false;
}
};
sonarComponents.setSensorContext(context);
context.fileSystem().add(new TestInputFileBuilder("", file.getPath()).setCharset(StandardCharsets.UTF_8).build());
return sonarComponents;
}
use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.
the class SurefireSensorTest method should_execute_if_filesystem_contains_java_files.
@Test
public void should_execute_if_filesystem_contains_java_files() {
surefireSensor = new SurefireSensor(new SurefireJavaParser(perspectives, javaResourceLocator), new MapSettings().asConfig(), fs, pathResolver);
DefaultSensorDescriptor defaultSensorDescriptor = new DefaultSensorDescriptor();
surefireSensor.describe(defaultSensorDescriptor);
assertThat(defaultSensorDescriptor.languages()).containsOnly("java");
}
Aggregations