### Question:
CreditRepository { @NonNull public Completable fetchCreditDrafts() { return creditService.getCreditDrafts() .subscribeOn(Schedulers.io()) .observeOn(Schedulers.computation()) .flatMapObservable(Observable::fromIterable) .map(creditDraftMapper) .toList() .doOnSuccess(store::replaceAll) .toCompletable(); } @Inject  CreditRepository(@NonNull final ReactiveStore<String, CreditDraft> store,
                     @NonNull final CreditService creditService,
                     @NonNull final CreditDraftMapper creditDraftMapper); @NonNull Observable<Option<List<CreditDraft>>> getAllCreditDrafts(); @NonNull Completable fetchCreditDrafts();  }### Answer:
@Test public void fetchCreditDraftsEmitsErrorWhenNetworkServiceErrors() { Throwable throwable = Mockito.mock(Throwable.class); new ArrangeBuilder().withErrorInCreditDraftsFromService(throwable); repository.fetchCreditDrafts().test().assertError(throwable); }
@Test public void creditDraftRawItemsFromServiceAreMapped() throws Exception { List<CreditDraftRaw> rawList = createRawList(); new ArrangeBuilder().withCreditDraftsFromService(rawList) .withMappedCredit(Mockito.mock(CreditDraft.class)); repository.fetchCreditDrafts().subscribe(); Mockito.verify(mapper).apply(rawList.get(0)); Mockito.verify(mapper).apply(rawList.get(1)); Mockito.verify(mapper).apply(rawList.get(2)); }
@Test public void creditDraftsAreStoredInStoreViaReplaceAll() throws Exception { CreditDraft safe = Mockito.mock(CreditDraft.class); new ArrangeBuilder().withCreditDraftsFromService(Collections.singletonList(Mockito.mock(CreditDraftRaw.class))) .withMappedCredit(safe); repository.fetchCreditDrafts().subscribe(); Mockito.verify(store).replaceAll(Collections.singletonList(safe)); }