### Question:
MonitorUtils { public static String waitFor(Process process) { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); @SuppressWarnings("resource") StreamGobbler gobblerOut = new StreamGobbler(process.getInputStream(), bytesOut, null); gobblerOut.start(); ByteArrayOutputStream bytesErr = new ByteArrayOutputStream(); @SuppressWarnings("resource") StreamGobbler gobblerErr = new StreamGobbler(process.getErrorStream(), bytesErr, null); gobblerErr.start(); try { process.waitFor(); gobblerOut.blockUntilFinished(); gobblerErr.blockUntilFinished(); if (bytesErr.size() > 0) { throw new ProcessHasStderr(bytesErr.toByteArray()); } return new String(bytesOut.toByteArray()); } catch (Exception e) { throw Throwables.propagate(e); } finally { if (gobblerOut.isAlive()) gobblerOut.interrupt(); if (gobblerErr.isAlive()) gobblerErr.interrupt(); } }  static boolean isUrlUp(URL url); static boolean isPidRunning(int pid); static boolean isPidRunning(int pid, String regex); static List<Integer> getRunningPids(String regex); static List<Integer> getRunningPids(String regex, String excludingRegex); static MemoryUsage getMemoryUsage(int pid); static MemoryUsage getMemoryUsage(int pid, String clazzRegexOfInterest, int minInstancesOfInterest); static List<String> searchLog(File file, String grepOfInterest); static List<String> searchLog(File file, String grepOfInterest, Set<String> grepExclusions); static Process exec(String cmd); static String waitFor(Process process); static int findOwnPid();  }### Answer:
@Test(enabled=false, timeOut=1000) public void testExecuteAndWaitFor() throws Exception { Process process = createDumpingProcess(false); process.waitFor(); fail("Should block while waiting to consume process output"); }
@Test(enabled=false, timeOut=1000) public void testExecuteAndWaitForErr() throws Exception { Process process = createDumpingProcess(true); process.waitFor(); fail("Should block while waiting to consume process output"); }
@Test(timeOut=1000) public void testExecuteAndWaitForConsumingOutputStream() throws Exception { Process process = createDumpingProcess(false); String out = MonitorUtils.waitFor(process); assertTrue(out.length() > 100000, "out.size="+out.length()); }
@Test(timeOut=1000, expectedExceptions=IllegalStateException.class) public void testExecuteAndWaitForConsumingErrorStream() throws Exception { Process process = createDumpingProcess(true); MonitorUtils.waitFor(process); }