@Test public void testHandleStatusStopDisable() { Action0 startStatusMock = mock(Action0.class); Action0 stopStatusMock = mock(Action0.class); Action0 enableStatusMock = mock(Action0.class); Action0 disableStatusMock = mock(Action0.class); OpenSession openSession = OpenSession.newSession(() -> "*#17*REQUEST"); openSession.addAllResponse(Lists.newArrayList(() -> "*17*2*0##", () -> "*17*4*0##", () -> "*#*1##")); Observable.just(openSession) .map(handleStatus(startStatusMock, stopStatusMock, enableStatusMock, disableStatusMock)) .subscribe(); verify(stopStatusMock).call(); verify(disableStatusMock).call(); verify(startStatusMock, never()).call(); verify(enableStatusMock, never()).call(); }
public static Func1<OpenSession, OpenSession> handleStatus( Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 2 || response.size() == 3, "invalid response"); checkNotNull(response.get(0).getValue(), "response value is null"); boolean isStatusHandled = false; if (FluentIterable.from(response).filter(value -> isStarted(value.getValue())).size() == 1) { startStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isStopped(value.getValue())).size() == 1) { stopStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isEnabled(value.getValue())).size() == 1) { enableStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isDisabled(value.getValue())).size() == 1) { disableStatus.call(); isStatusHandled = true; } if (!isStatusHandled) { throw new IllegalStateException("unhandled scenario status"); } return openSession; }; }
Scenario extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus( Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 2 || response.size() == 3, "invalid response"); checkNotNull(response.get(0).getValue(), "response value is null"); boolean isStatusHandled = false; if (FluentIterable.from(response).filter(value -> isStarted(value.getValue())).size() == 1) { startStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isStopped(value.getValue())).size() == 1) { stopStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isEnabled(value.getValue())).size() == 1) { enableStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isDisabled(value.getValue())).size() == 1) { disableStatus.call(); isStatusHandled = true; } if (!isStatusHandled) { throw new IllegalStateException("unhandled scenario status"); } return openSession; }; } }
Scenario extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus( Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 2 || response.size() == 3, "invalid response"); checkNotNull(response.get(0).getValue(), "response value is null"); boolean isStatusHandled = false; if (FluentIterable.from(response).filter(value -> isStarted(value.getValue())).size() == 1) { startStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isStopped(value.getValue())).size() == 1) { stopStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isEnabled(value.getValue())).size() == 1) { enableStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isDisabled(value.getValue())).size() == 1) { disableStatus.call(); isStatusHandled = true; } if (!isStatusHandled) { throw new IllegalStateException("unhandled scenario status"); } return openSession; }; } private  Scenario(String value); }
Scenario extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus( Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 2 || response.size() == 3, "invalid response"); checkNotNull(response.get(0).getValue(), "response value is null"); boolean isStatusHandled = false; if (FluentIterable.from(response).filter(value -> isStarted(value.getValue())).size() == 1) { startStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isStopped(value.getValue())).size() == 1) { stopStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isEnabled(value.getValue())).size() == 1) { enableStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isDisabled(value.getValue())).size() == 1) { disableStatus.call(); isStatusHandled = true; } if (!isStatusHandled) { throw new IllegalStateException("unhandled scenario status"); } return openSession; }; } private  Scenario(String value); static Scenario requestStart(String where); static Scenario requestStart(String where, Version version); static Scenario requestStop(String where); static Scenario requestStop(String where, Version version); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Scenario requestStatus(String where); static Scenario requestStatus(String where, Version version); static Func1<OpenSession, OpenSession> handleStatus(
            Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus); }
Scenario extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus( Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 2 || response.size() == 3, "invalid response"); checkNotNull(response.get(0).getValue(), "response value is null"); boolean isStatusHandled = false; if (FluentIterable.from(response).filter(value -> isStarted(value.getValue())).size() == 1) { startStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isStopped(value.getValue())).size() == 1) { stopStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isEnabled(value.getValue())).size() == 1) { enableStatus.call(); isStatusHandled = true; } if (FluentIterable.from(response).filter(value -> isDisabled(value.getValue())).size() == 1) { disableStatus.call(); isStatusHandled = true; } if (!isStatusHandled) { throw new IllegalStateException("unhandled scenario status"); } return openSession; }; } private  Scenario(String value); static Scenario requestStart(String where); static Scenario requestStart(String where, Version version); static Scenario requestStop(String where); static Scenario requestStop(String where, Version version); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Scenario requestStatus(String where); static Scenario requestStatus(String where, Version version); static Func1<OpenSession, OpenSession> handleStatus(
            Action0 startStatus, Action0 stopStatus, Action0 enableStatus, Action0 disableStatus);  }