@Test
public void testOutFile() throws Exception {

    final Console console = getMockConsole();
    when(console.getCwd()).thenReturn(tempDir);
    Options.Builder builder = new Options.Builder().setOutputJson(true);
    final File outFile = new File(tempDir, "testOutFile.json");
    builder.setOutFile(outFile);
    final DisposablePrinter printer = new Main.DisposablePrinterImpl(new PrintWriter(outFile));
    when(console.openPrinter(outFile)).thenReturn(Result.success(printer));
    final Result<Options> options = builder.build(console);
    options.stream().forEachOrdered(opts -> {
        opts.getPrinter().apply(() -> JavaxJson.key("message", "test").get()).get();
    });
    printer.dispose();
    try (Reader fileReader = new InputStreamReader(new FileInputStream(outFile), StandardCharsets.UTF_8);
         JsonReader reader = Json.createReader(fileReader)) {
        JsonObject json = reader.readObject();
        assertTrue("json should have 'message' key", json.containsKey("message"));
    }
}