SurefireUtils { public static List<File> getReportsDirectories(Configuration settings, FileSystem fs, PathResolver pathResolver) { List<File> dirs = getReportsDirectoriesFromProperty(settings, fs, pathResolver); if (dirs != null) { return dirs; } return Collections.singletonList(new File(fs.baseDir(), "target/surefire-reports")); } private  SurefireUtils(); static List<File> getReportsDirectories(Configuration settings, FileSystem fs, PathResolver pathResolver); static final String SUREFIRE_REPORT_PATHS_PROPERTY; }
@Test 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() .isDirectory(); File directory2 = directories.get(1); assertThat(directory2) .exists() .isDirectory(); assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty(); }
@Test 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).doesNotExist(); assertThat(directory.isDirectory()).isFalse(); assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty(); }