StockMovementsPresenter extends Presenter { protected Observable<List<StockMovementViewModel>> loadStockMovementViewModelsObserver() { return Observable.create((Observable.OnSubscribe<List<StockMovementViewModel>>) subscriber -> { try { List<StockMovementViewModel> list = from(stockMovementRepository.listLastFiveStockMovements(stockCard.getId())) .transform(stockMovementItem -> new StockMovementViewModel(stockMovementItem)).toList(); subscriber.onNext(list); subscriber.onCompleted(); } catch (LMISException e) { subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } StockMovementsPresenter(); @Override void attachView(BaseView v); void setStockCard(long stockCardId); void loadStockMovementViewModels(); void archiveStockCard();  }
@Test public void shouldLoadStockMovementViewModelsObserver() throws Exception { when(mockStockMovementRepository.listLastFiveStockMovements((long) anyInt())).thenReturn(new ArrayList<StockMovementItem>()); TestSubscriber<List<StockMovementViewModel>> subscriber = new TestSubscriber<>(); stockMovementsPresenter.loadStockMovementViewModelsObserver().subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); subscriber.assertValue(new ArrayList<StockMovementViewModel>()); }