### Question:
Commander { public byte[] execute(byte[] source, String... cmd) throws IOException, InterruptedException, IllegalStateException { ProcessBuilder builder = new ProcessBuilder(); builder.command(cmd); builder.redirectErrorStream(true); Process process = builder.start(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Thread processStdoutReader = readProcessStdout(process, buffer); OutputStream stdin = process.getOutputStream(); stdin.write(source); stdin.flush(); stdin.close(); process.waitFor(this.commandTimeout.duration(), this.commandTimeout.timeUnit()); processStdoutReader.join(readStdoutTimeout.millis()); byte[] output = buffer.toByteArray(); if (process.isAlive()) { process.destroyForcibly(); throw new InterruptedIOException("Process was forcibly killed (not responding after " + this.commandTimeout + " seconds)"); } int exitValue = process.exitValue(); if (exitValue != 0) { String errorMessage = new String(output); throw new IllegalStateException(errorMessage + " (exit code " + exitValue + ")"); } else { return output; } } Commander(JsonObject config); byte[] execute(byte[] source, String... cmd);  }### Answer:
@Test void should_throw_an_exception_when_bin_not_found() { assertThatThrownBy(() -> new Commander(new JsonObject()).execute("".getBytes(), "/path/not/found/dot")) .isInstanceOf(IOException.class) .hasMessageStartingWith("Cannot run program \"/path/not/found/dot\""); }
@Test void should_convert_diagram() throws IOException, InterruptedException { if (Files.isExecutable(Paths.get("/usr/bin/dot"))) { String source = read("hello.dot"); byte[] result = new Commander(new JsonObject()).execute(source.getBytes(), "dot", "-T", "svg"); String output = new String(result); assertThat(output.trim()).isEqualTo(read("hello.expected.svg").trim()); } }
@Test void should_convert_large_diagram() throws IOException, InterruptedException { if (Files.isExecutable(Paths.get("/usr/bin/node"))) { String source = read("./volcano.vega"); byte[] result = new Commander(new JsonObject()).execute(source.getBytes(), "node", "../vega/index.js", "--output-format", "svg"); String output = new String(result); assertThat(output.trim()).isEqualTo(read("volcano.expected.svg").trim()); } }