### Question:
UastGeneratorWrapper { UastNode createUast(InputStream source) throws IOException, InterruptedException { Process process = processBuilder.start(); errorConsumer.consumeStream(process.getErrorStream(), LOG::debug); try (OutputStream out = process.getOutputStream(); InputStream in = process.getInputStream()) { copy(source, process.getOutputStream()); out.close(); UastNode uastNode = UastNode.from(new InputStreamReader(in, StandardCharsets.UTF_8)); boolean exited = process.waitFor(5, TimeUnit.SECONDS); if (exited && process.exitValue() != 0) { throw new IllegalStateException("Parser returned non-zero exit value: " + process.exitValue()); } if (process.isAlive()) { process.destroyForcibly(); throw new IllegalStateException("Took too long to parse. External process killed forcibly"); } return uastNode; } } UastGeneratorWrapper(SensorContext sensorContext);   UastGeneratorWrapper(Command command);   }### Answer:
@Test void test() throws Exception { SensorContextTester sensorContext = SensorContextTester.create(workDir); sensorContext.fileSystem().setWorkDir(workDir.toPath()); UastGeneratorWrapper generator = new UastGeneratorWrapper(sensorContext); ByteArrayInputStream in = new ByteArrayInputStream("package main\nfunc foo() {}".getBytes(StandardCharsets.UTF_8)); UastNode uast = generator.createUast(in); assertThat(uast.joinTokens()).isEqualTo("package main\n" + "func foo() {}"); }
@Test void test_non_zero_return_value() throws Exception { String cp = System.getProperty("java.class.path"); UastGeneratorWrapper generator = new UastGeneratorWrapper(() -> Arrays.asList("java", "-cp", cp, ExternalProcess.class.getCanonicalName(), "{kinds: []}", "2")); assertThatThrownBy(() -> generator.createUast(new ByteArrayInputStream(new byte[] {}))) .isInstanceOf(IllegalStateException.class); }
@Test void test_stuck_process() throws Exception { String cp = System.getProperty("java.class.path"); UastGeneratorWrapper generator = new UastGeneratorWrapper(() -> Arrays.asList("java", "-cp", cp, StuckExternalProcess.class.getCanonicalName(), "{kinds: []}")); assertThatThrownBy(() -> generator.createUast(new ByteArrayInputStream(new byte[] {}))) .isInstanceOf(IllegalStateException.class) .hasMessage("Took too long to parse. External process killed forcibly"); }