IoUtils { public static String runCommand(String command) { return runCommand(command, Paths.get(System.getProperty("user.dir"))); } private  IoUtils(); static byte[] toByteArray(InputStream is); static String toUtf8String(InputStream is); static String readUtf8File(String path); static String readUtf8File(Path path); static String readUtf8Resource(ClassLoader classLoader, String resourcePath); static String readUtf8Resource(Class<?> clazz, String resourcePath); static String readUtf8Url(URL url); static String runCommand(String command); static String runCommand(String command, Path directory); static int runCommand(String command, Path directory, Appendable output);  }
@Test public void throwsWhenProcessFails() { RuntimeException e = Assertions.assertThrows(RuntimeException.class, () -> { IoUtils.runCommand("thisCommandDoesNotExist" + new Random().nextInt(1000)); }); assertThat(e.getMessage(), containsString("failed with exit code")); }
@Test public void doesNotThrowWhenGivenOutput() { StringBuilder sb = new StringBuilder(); String name = "thisCommandDoesNotExist" + new Random().nextInt(1000); int code = IoUtils.runCommand(name, Paths.get(System.getProperty("user.dir")), sb); assertThat(code, not(0)); assertThat(sb.toString(), not(emptyString())); }