@Test public void should_process_json_payload_from_provider() { ServiceResponse response = ServiceResponse.create(DateTime.now(), Collections.singletonList(Animal.create("Doggy", "dog"))); when(api.loadProviderJson(any())).thenReturn(Single.just(response)); TestObserver<ServiceResponse> observer = service.fetchResponse(DateTime.now()).test(); observer.assertNoErrors(); observer.assertValue(response); }
@NonNull @Override public Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime) { try { return api.loadProviderJson(DateHelper.encodeDate(dateTime)) .onErrorResumeNext(this::mapError); } catch (UnsupportedEncodingException e) { return Single.error(e); } }
Service implements Repository { @NonNull @Override public Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime) { try { return api.loadProviderJson(DateHelper.encodeDate(dateTime)) .onErrorResumeNext(this::mapError); } catch (UnsupportedEncodingException e) { return Single.error(e); } } }
Service implements Repository { @NonNull @Override public Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime) { try { return api.loadProviderJson(DateHelper.encodeDate(dateTime)) .onErrorResumeNext(this::mapError); } catch (UnsupportedEncodingException e) { return Single.error(e); } } @Inject  Service(@NonNull Api api); }
Service implements Repository { @NonNull @Override public Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime) { try { return api.loadProviderJson(DateHelper.encodeDate(dateTime)) .onErrorResumeNext(this::mapError); } catch (UnsupportedEncodingException e) { return Single.error(e); } } @Inject  Service(@NonNull Api api); @NonNull @Override Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime); }
Service implements Repository { @NonNull @Override public Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime) { try { return api.loadProviderJson(DateHelper.encodeDate(dateTime)) .onErrorResumeNext(this::mapError); } catch (UnsupportedEncodingException e) { return Single.error(e); } } @Inject  Service(@NonNull Api api); @NonNull @Override Single<ServiceResponse> fetchResponse(@NonNull DateTime dateTime);  }