use of org.sonar.api.batch.fs.internal.DefaultFileSystem 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.batch.fs.internal.DefaultFileSystem 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.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class XmlFileSensorTest method test_issues_creation.
@Test
public void test_issues_creation() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven/").getAbsoluteFile());
DefaultFileSystem fs = context.fileSystem();
final File file = new File("src/test/files/maven/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, times(1)).reportIssue(Mockito.argThat(argument -> file.getAbsolutePath().equals(argument.getFile().getAbsolutePath())));
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class XmlFileSensorTest method not_executed_without_xml_files_in_file_system.
@Test
public void not_executed_without_xml_files_in_file_system() throws Exception {
SensorContextTester context = SensorContextTester.create(new File("src/test/files/maven/"));
DefaultFileSystem fs = context.fileSystem();
SonarComponents sonarComponents = createSonarComponentsMock(fs);
XmlFileSensor sensor = new XmlFileSensor(sonarComponents, fs);
sensor.execute(context);
verify(sonarComponents, Mockito.never()).reportIssue(any());
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class XmlFileSensorTest method setUp.
@Before
public void setUp() {
DefaultFileSystem fileSystem = new DefaultFileSystem(new File(""));
sensor = new XmlFileSensor(mock(SonarComponents.class), fileSystem);
}
Aggregations