CoberturaImporter { public CoverageReport read(List<Path> allCoverageFiles) throws SAXException, IOException { final List<Path> coverageFiles = allCoverageFiles .stream() .filter(f -> { try (Stream<String> executedLines = Files.lines(f).parallel() .filter(s -> s.matches(".*hits=\"[1-9].*"))) { if (executedLines.findFirst().isPresent()) { return true; } else { System.err.println(String.format( "Did not add file %s as it did not execute a single node.", f.getFileName())); return false; } } catch (final Exception e) { throw new RuntimeException(e); } }).collect(Collectors.toList()); if (coverageFiles.isEmpty()) return new CoverageReport(ImmutableList.of(), ImmutableList.of()); Path firstFile = coverageFiles.get(0); files = parseForSourceCodeFiles(firstFile); filesForNames = files.stream().collect(Collectors.toMap(f -> f.getFileName(), f -> f)); Map<Path, TestCase> testCaseMap = coverageFiles.stream() .collect(Collectors.toMap(p -> p, p -> { String fileName = p.getFileName().toString(); assert fileName.startsWith("p_") || fileName.startsWith("f_"); boolean passed = fileName.startsWith("p_"); return new TestCase(fileName.substring(2), passed); })); CoverageReport report = new CoverageReport(files, testCaseMap.values()); testCaseMap .entrySet() .stream() .parallel() .forEach(e -> processFile(report, e.getKey(), e.getValue())); return report; } CoberturaImporter(); CoverageReport read(List<Path> allCoverageFiles);  }
@Test public void testImport() throws URISyntaxException, SAXException, IOException { Path file = Paths.get(getClass().getResource("p_cobertura.xml").toURI()); CoberturaImporter importer = new CoberturaImporter(); CoverageReport report = importer.read(ImmutableList.of(file)); assertThat(report.getFiles() .stream() .map(f -> f.getFileName()) .collect(Collectors.toList()), containsInAnyOrder(FILE_NAMES)); assertThat(report.getTestCases() .stream() .map(f -> f.getName()) .collect(Collectors.toList()), containsInAnyOrder(TEST_CASES)); SourceCodeFile testFile = report.getFiles() .stream() .filter(f -> f.getFileName().equals(FILE_NAMES[0])) .findFirst() .orElseThrow(RuntimeException::new); FileCoverage coverage = report.getCoverage(report.getTestCases().get(0), testFile); assertThat(coverage.isCovered(29), is(true)); assertThat(coverage.isCovered(57), is(false)); }