### Question:
JSchSshTerminal { public void setExpectationTimeout(final long expectationTimeout) { if (expectationTimeout == -1 || expectationTimeout > 0) { this.expectationTimeout = expectationTimeout; } } JSchSshTerminal();  JSchSshTerminal(final ConnectionPool pool); TerminalResponse executeCommandGroups(final List<CommandExpectationGroup> commandExpectationGroups); void setOutputStream(final OutputStream stream); void setExpectationTimeout(final long expectationTimeout);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testExpectationTimeoutForExecuteCommandGroups() throws Exception { final JSchSshTerminal timeoutTerminal = new JSchSshTerminal(pool); 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); final ArgumentCaptor<Long> captor = ArgumentCaptor.forClass(Long.class); final String osPromptValue = TerminalProperties.getGlobalTerminalProperties().getOsPromptPattern(); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); timeoutTerminal.setExpectationTimeout(301); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); timeoutTerminal.setExpectationTimeout(0); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); timeoutTerminal.setExpectationTimeout(1234); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); timeoutTerminal.setExpectationTimeout(-10); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); timeoutTerminal.setExpectationTimeout(-1); executeCommandsHelper(timeoutTerminal, Arrays.asList(new String[] { "some command", "command ending with go" }), null); verify(expect, times(12)).expect(argumentCaptorListMatch.capture()); boolean defaultOsPromptWasExpectedAtLeastOnce = false; for (final List<Match> matches : argumentCaptorListMatch.getAllValues()) { for (final Match match : matches) { final String pattern = ((RegExpMatch) match).getPattern().getPattern(); assertThat(pattern).isNotEmpty(); if (pattern.equals(osPromptValue)) { defaultOsPromptWasExpectedAtLeastOnce = true; } } } assertThat(defaultOsPromptWasExpectedAtLeastOnce).as("exected an expectation for the default OS prompt") .isTrue(); verify(expect, times(18)).setDefaultTimeout(captor.capture()); final List<Long> values = captor.getAllValues(); assertThat(values.get(0)).isEqualTo(20000); assertThat(values.get(1)).isEqualTo(20000); assertThat(values.get(2)).isEqualTo(-1); assertThat(values.get(3)).isEqualTo(301); assertThat(values.get(4)).isEqualTo(301); assertThat(values.get(5)).isEqualTo(-1); assertThat(values.get(6)).isEqualTo(301); assertThat(values.get(7)).isEqualTo(301); assertThat(values.get(8)).isEqualTo(-1); assertThat(values.get(9)).isEqualTo(1234); assertThat(values.get(10)).isEqualTo(1234); assertThat(values.get(11)).isEqualTo(-1); assertThat(values.get(12)).isEqualTo(1234); assertThat(values.get(13)).isEqualTo(1234); assertThat(values.get(14)).isEqualTo(-1); assertThat(values.get(15)).isEqualTo(-1); assertThat(values.get(16)).isEqualTo(-1); assertThat(values.get(17)).isEqualTo(-1); }