### Question:
JSchSshTerminal { public void setOutputStream(final OutputStream stream) { this.stream = stream; } JSchSshTerminal();  JSchSshTerminal(final ConnectionPool pool); TerminalResponse executeCommandGroups(final List<CommandExpectationGroup> commandExpectationGroups); void setOutputStream(final OutputStream stream); void setExpectationTimeout(final long expectationTimeout);  }### Answer:
@Test public void testExecuteReturnCode() throws Exception { assertThat(executeCommandsHelper(terminal, Arrays.asList("echo hello"), "osPromptPattern").getExitStatus()) .isEqualTo(Integer.MAX_VALUE); final ArgumentCaptor<OutputStream> fileCaptor = ArgumentCaptor.forClass(OutputStream.class); verify(shell).setOutputStream(fileCaptor.capture()); fileCaptor.getValue().close(); }
@Test public void testSetOutputStream() throws Exception { final OutputStream stream = mock(OutputStream.class); when(shell.isClosed()).thenReturn(Boolean.TRUE); terminal.setOutputStream(stream); executeCommandsHelper(terminal, Arrays.asList("I am a command"), "osPromptPattern"); verify(shell, times(1)).setOutputStream(stream); }
@SuppressWarnings("unchecked") @Test public void testOSPromptPatternIsHonored() throws Exception { final JSchSshTerminal timeoutTerminal = new JSchSshTerminal(); final ExpectState expectState = mock(ExpectState.class); when(expectState.getMatch(0)).thenReturn("match string"); final Expect4j expect = mock(Expect4j.class); when(expect.expect(any(List.class))).thenReturn(1); when(expect.getLastState()).thenReturn(expectState); whenNew(Expect4j.class).withAnyArguments().thenReturn(expect); executeCommandsHelper(timeoutTerminal, Collections.singletonList("blarg!"), "os-prompt-pattern>>"); final ArgumentCaptor<OutputStream> fileCaptor = ArgumentCaptor.forClass(OutputStream.class); verify(expect).send("blarg!"); verify(expect).send("\r"); verify(expect).expect(argumentCaptorListMatch.capture()); assertThat(argumentCaptorListMatch.getAllValues().size()).isEqualTo(1); assertThat(((RegExpMatch) argumentCaptorListMatch.getAllValues().get(0).get(0)).getPattern().getPattern()) .isEqualTo("os-prompt-pattern>>"); verify(shell).setOutputStream(fileCaptor.capture()); fileCaptor.getValue().close(); }