@Test public void closeStreams_ignores_failure_if_stream_fails_to_be_closed() throws Exception { InputStream stream = mock(InputStream.class); doThrow(new IOException("error")).when(stream).close(); Process process = mock(Process.class); when(process.getInputStream()).thenReturn(stream); ProcessCommandsProcessMonitor underTest = new ProcessCommandsProcessMonitor(process, null, mock(ProcessCommands.class, Mockito.RETURNS_MOCKS)); // no failures underTest.closeStreams(); } }
@Test public void closeStreams_ignores_null_stream() { ProcessCommands commands = mock(ProcessCommands.class); Process process = mock(Process.class); when(process.getInputStream()).thenReturn(null); ProcessCommandsProcessMonitor underTest = new ProcessCommandsProcessMonitor(process, null, commands); // no failures underTest.closeStreams(); }
@Test public void ProcessMonitorImpl_is_a_proxy_of_Process() throws Exception { Process process = mock(Process.class, RETURNS_DEEP_STUBS); ProcessCommands commands = mock(ProcessCommands.class, RETURNS_DEEP_STUBS); ProcessCommandsProcessMonitor underTest = new ProcessCommandsProcessMonitor(process, ProcessId.WEB_SERVER, commands); underTest.waitFor(); verify(process).waitFor(); underTest.closeStreams(); verify(process.getErrorStream()).close(); verify(process.getInputStream()).close(); verify(process.getOutputStream()).close(); underTest.destroyForcibly(); verify(process).destroyForcibly(); assertThat(underTest.getInputStream()).isNotNull(); underTest.isAlive(); verify(process).isAlive(); underTest.waitFor(123, TimeUnit.MILLISECONDS); verify(process).waitFor(123, TimeUnit.MILLISECONDS); }