@Test
public void testWriteReports() {

    final List<CheckReport> reports = new ArrayList<>();
    reports.add(new SimpleReport("some check", Collections.emptyList()));
    reports.add(new SimpleReport("check with violations", Arrays.asList(
            new SimpleViolation(Severity.MINOR, "minor violation"),
            new SimpleViolation(Severity.SEVERE, "severe violation with one packageId",
                    PackageId.fromString("my_packages/acme/1.0")),
            new SimpleViolation(Severity.MAJOR, "major violation with several packageIds",
                    PackageId.fromString("my_packages/alpha/1.0"),
                    PackageId.fromString("my_packages/beta/1.0"),
                    PackageId.fromString("my_packages/gamma/1.0"))
    )));
    final String output = captureStructured(false, (command, printer) ->
            command.printReports(reports, printer));
    LOGGER.info("reports: \n{}", output);
    assertFalse("reports should not be empty", output.isEmpty());
    final String jsonOutput = captureStructured(true, (command, printer) ->
            command.printReports(reports, printer));
    LOGGER.info("json reports: \n{}", jsonOutput);
    assertFalse("json reports should not be empty", jsonOutput.isEmpty());
    List<CheckReport> readReports = uncheck0(() ->
            ReportMapper.readReports(() -> new BufferedReader(new StringReader(jsonOutput)))).get();
    for (int i = 0; i < reports.size(); i++) {
        assertEquals("read report should match input report at index " + i,
                reports.get(i), readReports.get(i));
    }
}