SoundSystem extends BaseOpenMessage { public static Func1<OpenSession, OpenSession> handleStatus(Action0 onStatus, Action0 offStatus) { return openSession -> { isValidPrefixType(openSession.getRequest(), FORMAT_PREFIX_DIMENSION_WHO, WHO_16); List<OpenMessage> response = openSession.getResponse(); checkNotNull(response, "response is null"); checkArgument(response.size() >= 1, "invalid response"); if (isOn(openSession.getRequest(), response)) { onStatus.call(); } else { offStatus.call(); } return openSession; }; } protected  SoundSystem(String value); static SoundSystem requestTurnOn(String where, Type type, Source source); static SoundSystem requestTurnOff(String where, Type type, Source source); static Func1<OpenSession, OpenSession> handleResponse(Action0 onSuccess, Action0 onFail); static SoundSystem requestStatus(String where, Type type); static Func1<OpenSession, OpenSession> handleStatus(Action0 onStatus, Action0 offStatus); static SoundSystem requestVolumeUp(String where, Type type); static SoundSystem requestVolumeDown(String where, Type type); static SoundSystem requestStationUp(String where, Type type); static SoundSystem requestStationDown(String where, Type type);  }
@Test public void testHandleStatusOn() { Action0 onStatusMock = mock(Action0.class); Action0 offStatusMock = mock(Action0.class); OpenSession openSession = OpenSession.newSession(() -> "*#16*REQUEST"); openSession.addAllResponse(Lists.newArrayList(() -> "*16*3*01##", () -> "*#*1##")); Observable.just(openSession) .map(SoundSystem.handleStatus(onStatusMock, offStatusMock)) .subscribe(); verify(onStatusMock).call(); verify(offStatusMock, never()).call(); }