@Test public void testHandleStatusUp() { Action0 stopAction = mock(Action0.class); Action0 upAction = mock(Action0.class); Action0 downAction = mock(Action0.class); OpenSession openSession = OpenSession.newSession(() -> "*#2*REQUEST"); openSession.addAllResponse(Lists.newArrayList(() -> "*2*1*21##", () -> "*#*1##")); Observable.just(openSession) .map(Automation.handleStatus(stopAction, upAction, downAction)) .subscribe(); verify(upAction).call(); verify(stopAction, never()).call(); verify(downAction, never()).call(); }
public static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 1 || response.size() == 2, "invalid response"); final String responseValue = response.get(0).getValue(); checkNotNull(responseValue, "response value is null"); if (isStop(responseValue)) { stopAction.call(); return openSession; } if (isUp(responseValue)) { upAction.call(); return openSession; } if (isDown(responseValue)) { downAction.call(); return openSession; } throw new IllegalStateException("unhandled automation status"); }; }
Automation extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 1 || response.size() == 2, "invalid response"); final String responseValue = response.get(0).getValue(); checkNotNull(responseValue, "response value is null"); if (isStop(responseValue)) { stopAction.call(); return openSession; } if (isUp(responseValue)) { upAction.call(); return openSession; } if (isDown(responseValue)) { downAction.call(); return openSession; } throw new IllegalStateException("unhandled automation status"); }; } }
Automation extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 1 || response.size() == 2, "invalid response"); final String responseValue = response.get(0).getValue(); checkNotNull(responseValue, "response value is null"); if (isStop(responseValue)) { stopAction.call(); return openSession; } if (isUp(responseValue)) { upAction.call(); return openSession; } if (isDown(responseValue)) { downAction.call(); return openSession; } throw new IllegalStateException("unhandled automation status"); }; } private  Automation(String value); }
Automation extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 1 || response.size() == 2, "invalid response"); final String responseValue = response.get(0).getValue(); checkNotNull(responseValue, "response value is null"); if (isStop(responseValue)) { stopAction.call(); return openSession; } if (isUp(responseValue)) { upAction.call(); return openSession; } if (isDown(responseValue)) { downAction.call(); return openSession; } throw new IllegalStateException("unhandled automation status"); }; } private  Automation(String value); static Automation requestStop(String where); static Automation requestStop(String where, Type type, String bus); static Automation requestMoveUp(String where); static Automation requestMoveUp(String where, Type type, String bus); static Automation requestMoveDown(String where); static Automation requestMoveDown(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Automation requestStatus(String where); static Automation requestStatus(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction); static boolean isValidRangeType(String where, Type type, String bus); }
Automation extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_STATUS_WHO, WHO); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() == 1 || response.size() == 2, "invalid response"); final String responseValue = response.get(0).getValue(); checkNotNull(responseValue, "response value is null"); if (isStop(responseValue)) { stopAction.call(); return openSession; } if (isUp(responseValue)) { upAction.call(); return openSession; } if (isDown(responseValue)) { downAction.call(); return openSession; } throw new IllegalStateException("unhandled automation status"); }; } private  Automation(String value); static Automation requestStop(String where); static Automation requestStop(String where, Type type, String bus); static Automation requestMoveUp(String where); static Automation requestMoveUp(String where, Type type, String bus); static Automation requestMoveDown(String where); static Automation requestMoveDown(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static Automation requestStatus(String where); static Automation requestStatus(String where, Type type, String bus); static Func1<OpenSession, OpenSession> handleStatus(Action0 stopAction, Action0 upAction, Action0 downAction); static boolean isValidRangeType(String where, Type type, String bus);  }