use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class SonarComponentsTest method test_sonar_components.
@Test
void test_sonar_components() {
SensorContextTester sensorContextTester = spy(SensorContextTester.create(new File("")));
DefaultFileSystem fs = sensorContextTester.fileSystem();
ClasspathForTest javaTestClasspath = mock(ClasspathForTest.class);
List<File> javaTestClasspathList = Collections.emptyList();
when(javaTestClasspath.getElements()).thenReturn(javaTestClasspathList);
InputFile inputFile = TestUtils.emptyInputFile("foo.java");
fs.add(inputFile);
FileLinesContext fileLinesContext = mock(FileLinesContext.class);
when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext);
SonarComponents sonarComponents = new SonarComponents(fileLinesContextFactory, fs, null, javaTestClasspath, checkFactory);
sonarComponents.setSensorContext(sensorContextTester);
List<JavaCheck> visitors = sonarComponents.mainChecks();
assertThat(visitors).isEmpty();
Collection<JavaCheck> testChecks = sonarComponents.testChecks();
assertThat(testChecks).isEmpty();
assertThat(sonarComponents.getJavaClasspath()).isEmpty();
assertThat(sonarComponents.getJavaTestClasspath()).isEqualTo(javaTestClasspathList);
NewHighlighting newHighlighting = sonarComponents.highlightableFor(inputFile);
assertThat(newHighlighting).isNotNull();
verify(sensorContextTester, times(1)).newHighlighting();
NewSymbolTable newSymbolTable = sonarComponents.symbolizableFor(inputFile);
assertThat(newSymbolTable).isNotNull();
verify(sensorContextTester, times(1)).newSymbolTable();
assertThat(sonarComponents.fileLinesContextFor(inputFile)).isEqualTo(fileLinesContext);
assertThat(sonarComponents.context()).isSameAs(sensorContextTester);
ClasspathForMain javaClasspath = mock(ClasspathForMain.class);
List<File> list = mock(List.class);
when(javaClasspath.getElements()).thenReturn(list);
sonarComponents = new SonarComponents(fileLinesContextFactory, fs, javaClasspath, javaTestClasspath, checkFactory);
assertThat(sonarComponents.getJavaClasspath()).isEqualTo(list);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class ClasspathForMainTest method libraries_should_read_dir_of_class_files.
@Test
void libraries_should_read_dir_of_class_files() {
fs = new DefaultFileSystem(new File("src/test/files/"));
fs.add(TestUtils.emptyInputFile("foo.java"));
settings.setProperty(ClasspathProperties.SONAR_JAVA_LIBRARIES, "classpath");
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).hasSize(5);
settings.setProperty(ClasspathProperties.SONAR_JAVA_LIBRARIES, "classpath/");
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).hasSize(5);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class ClasspathForMainTest method createTwoFilesInFileSystem.
private void createTwoFilesInFileSystem() {
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
fs.add(TestUtils.emptyInputFile("plop.java"));
fs.add(TestUtils.emptyInputFile("bar.java"));
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class ClasspathForMainTest method classpath_empty_if_only_test_files.
@Test
void classpath_empty_if_only_test_files() throws Exception {
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
fs.add(TestUtils.emptyInputFile("plop.java", InputFile.Type.TEST));
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).isEmpty();
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class ClasspathForMainTest method sonar_binaries_should_not_check_for_existence_of_files_when_no_sources.
@Test
void sonar_binaries_should_not_check_for_existence_of_files_when_no_sources() throws Exception {
settings.setProperty(ClasspathProperties.SONAR_JAVA_BINARIES, "toto/**/hello.jar");
fs = new DefaultFileSystem(new File("src/test/files/classpath/"));
fs.add(TestUtils.emptyInputFile("plop.java", InputFile.Type.TEST));
javaClasspath = createJavaClasspath();
assertThat(javaClasspath.getElements()).isEmpty();
}
Aggregations