@Test public void getTestFiles() { final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getTestFiles(Java.INSTANCE).size(), is(1)); assertThat(fs.getTestFiles(Java.INSTANCE), hasItem(named("BarTest.java"))); }
@Test public void createSonarWorkingDirectory() { DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); java.io.File dir = fs.getSonarWorkingDirectory(); assertThat(dir.exists(), is(true)); assertThat(dir.listFiles().length, is(0)); }
@Test public void getJavaSourceFiles() { final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getJavaSourceFiles().size(), is(2)); assertThat(fs.getJavaSourceFiles(), hasItem(named("Bar.java"))); assertThat(fs.getJavaSourceFiles(), hasItem(named("Whizz.java"))); }
@Test public void getJapaneseCharSet() { project = MavenTestUtils.loadProjectFromPom( DefaultProjectFileSystemTest.class, "japanese-project/pom.xml"); DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getSourceCharset().name(), is("Shift_JIS")); }
@Test public void hasJavaSourceFiles() { final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.hasJavaSourceFiles(), is(true)); PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*.java"); project.setConfiguration(conf); assertThat(fs.hasJavaSourceFiles(), is(false)); }
/** See http://jira.codehaus.org/browse/SONAR-2266 */ @Test public void shouldReturnOnlyExistingSourceAndTestDirectories() { // in this example : "src/main/java" is a file, "src/test/java" doesn't exists project = MavenTestUtils.loadProjectFromPom( DefaultProjectFileSystemTest.class, "nonexistent-dirs/pom.xml"); DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getSourceDirs().size(), is(0)); assertThat(fs.getTestDirs().size(), is(0)); }
/** See http://jira.codehaus.org/browse/SONAR-2280 */ @Test public void resolvePathShouldReturnCanonicalFile() { MavenProject pom = mock(MavenProject.class); when(pom.getBasedir()).thenReturn(new File("/project")); Project project = new Project("foo").setPom(pom); DefaultProjectFileSystem fs = new DefaultProjectFileSystem(project, null); assertThat(fs.resolvePath(".").getAbsolutePath(), endsWith("project")); assertThat(fs.resolvePath("../project").getAbsolutePath(), endsWith("project")); }
@Test public void applyExclusionPatternsToSourceFiles() { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/B*.java"); project.setConfiguration(conf); final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getJavaSourceFiles().size(), is(1)); assertThat(fs.getJavaSourceFiles(), hasItem(named("Whizz.java"))); }
@Test public void doNotApplyExclusionPatternsToTestFiles() { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/B*.java"); project.setConfiguration(conf); final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getTestFiles(Java.INSTANCE).size(), is(1)); assertThat(fs.getTestFiles(Java.INSTANCE), hasItem(named("BarTest.java"))); }
/** See http://jira.codehaus.org/browse/SONAR-1449 */ @Test public void exclusionPatternOnAjFiles() { PropertiesConfiguration conf = new PropertiesConfiguration(); conf.setProperty(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY, "**/*.aj"); project.setConfiguration(conf); final DefaultProjectFileSystem fs = newDefaultProjectFileSystem(project); assertThat(fs.getSourceFiles(Java.INSTANCE).size(), is(2)); assertThat(fs.getSourceFiles(Java.INSTANCE), hasItem(named("Whizz.java"))); assertThat(fs.getSourceFiles(Java.INSTANCE), hasItem(named("Bar.java"))); }
@Test public void shouldUseExtendedFilters() { DefaultProjectFileSystem fsWithoutFilter = newDefaultProjectFileSystem(project); assertThat(fsWithoutFilter.getSourceFiles().size(), is(2)); assertThat(fsWithoutFilter.getSourceFiles(), hasItem(named("Bar.java"))); FileFilter filter = new FileFilter() { public boolean accept(File file) { return !StringUtils.equals(file.getName(), "Bar.java"); } }; DefaultProjectFileSystem fsWithFilter = new DefaultProjectFileSystem(project, new Languages(Java.INSTANCE), filter); assertThat(fsWithFilter.getSourceFiles().size(), is(1)); assertThat(fsWithFilter.getSourceFiles(), not(hasItem(named("Bar.java")))); }