### Question:
WorkerProcess extends Process { @Override public int exitValue() { int exitValue = delegate.exitValue(); shutdownHookRegistrar.removeShutdownHook(shutdownHook); return exitValue; } WorkerProcess(ProcessBuilder processBuilder); @VisibleForTesting  WorkerProcess(ShutdownHookRegistrar shutdownHookRegistrar, Process process); @Override OutputStream getOutputStream(); @Override InputStream getInputStream(); @Override InputStream getErrorStream(); @Override int waitFor(); @Override int exitValue(); @Override void destroy();  }### Answer:
@Test public void shutdownHook_exitValueThrows() throws Exception { verify(registrar).addShutdownHook(hookCaptor.capture()); when(delegate.exitValue()).thenThrow(new IllegalThreadStateException()); try { workerProcess.exitValue(); fail(); } catch (IllegalThreadStateException expected) {} verify(registrar, never()).removeShutdownHook(hookCaptor.getValue()); }
@Test public void shutdownHook_exitValue() throws Exception { verify(registrar).addShutdownHook(hookCaptor.capture()); when(delegate.exitValue()).thenReturn(0); workerProcess.exitValue(); verify(registrar).removeShutdownHook(hookCaptor.getValue()); }