Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A little enhancement of report #1303

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ public void should_create_xml_report_when_xml_option_is_provided()
assertTrue(xml.isFile());
}

@Test
public void should_create_xml_report_when_xml_option_is_provided_and_the_path_is_not_exist()
throws Exception {
File xml = new File(new File(tmp.getRoot(), "xml"), "coverage.xml");

execute("report", "--classfiles", getClassPath(), "--xml",
xml.getAbsolutePath());

assertOk();
assertTrue(xml.isFile());
}

@Test
public void should_create_csv_report_when_csv_option_is_provided()
throws Exception {
Expand All @@ -110,6 +122,18 @@ public void should_create_csv_report_when_csv_option_is_provided()
assertTrue(csv.isFile());
}

@Test
public void should_create_csv_report_when_csv_option_is_provided_and_the_path_is_not_exist()
throws Exception {
File csv = new File(new File(tmp.getRoot(), "csv"), "coverage.csv");

execute("report", "--classfiles", getClassPath(), "--csv",
csv.getAbsolutePath());

assertOk();
assertTrue(csv.isFile());
}

@Test
public void should_create_html_report_when_html_option_is_provided()
throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,24 @@ private void writeReports(final IBundleCoverage bundle,
visitor.visitEnd();
}

private void createParent(final File file) {
final File folder = file.getParentFile();
if (!folder.exists()) {
final boolean dr = folder.mkdirs();
}
}

private IReportVisitor createReportVisitor() throws IOException {
final List<IReportVisitor> visitors = new ArrayList<IReportVisitor>();

if (xml != null) {
createParent(xml);
final XMLFormatter formatter = new XMLFormatter();
visitors.add(formatter.createVisitor(new FileOutputStream(xml)));
}

if (csv != null) {
createParent(csv);
final CSVFormatter formatter = new CSVFormatter();
visitors.add(formatter.createVisitor(new FileOutputStream(csv)));
}
Expand Down