### Question:
BaseApiClient { @NonNull public Observable<FlowEvent> subscribeToSystemEvents() { if (!isProcessingServiceInstalled(context)) { return Observable.error(NO_FPS_EXCEPTION); } final ChannelClient deviceMessenger = getMessengerClient(SYSTEM_EVENT_SERVICE_COMPONENT); AppMessage appMessage = new AppMessage(REQUEST_MESSAGE, getInternalData()); return deviceMessenger .sendMessage(appMessage.toJson()) .map(FlowEvent::fromJson) .doFinally(deviceMessenger::closeConnection) .onErrorResumeNext(throwable -> { return Observable.error(createFlowException(throwable)); }); } protected  BaseApiClient(String apiVersion, Context context); @NonNull Completable initiateRequest(final Request request); Completable sendEvent(final FlowEvent flowEvent); @NonNull Observable<Response> queryResponses(@NonNull ResponseQuery responseQuery); @NonNull Single<List<Device>> getDevices(); @NonNull Observable<FlowEvent> subscribeToSystemEvents(); static boolean isProcessingServiceInstalled(Context context); @NonNull static String getProcessingServiceVersion(Context context); static final String FLOW_PROCESSING_SERVICE; }### Answer:
@Test public void subscribeToSystemEventsShouldSendAndReceiveCorrectly() throws Exception { pretendServiceIsInstalled(BaseApiClient.FLOW_PROCESSING_SERVICE_COMPONENT); AdditionalData additionalData = new AdditionalData(); additionalData.addData("test", "hello"); FlowEvent flowEvent = new FlowEvent("type", additionalData, "trigger"); when(messengerClient.sendMessage(anyString())).thenReturn(Observable.just(flowEvent.toJson())); TestObserver<FlowEvent> testObserver = apiBase.subscribeToSystemEvents().test(); AppMessage appMessage = callSendAndCaptureMessage(); assertThat(appMessage).isNotNull(); testObserver.assertValueCount(1); assertThat(testObserver.values().get(0)).isEqualTo(flowEvent); verify(messengerClient).closeConnection(); }
@Test public void subscribeToSystemEventsShouldErrorIfNoFps() throws Exception { TestObserver<FlowEvent> testObserver = apiBase.subscribeToSystemEvents().test(); assertThat(testObserver.assertError(BaseApiClient.NO_FPS_EXCEPTION)); }