ProductPresenter extends Presenter { public Observable<List<InventoryViewModel>> loadEmergencyProducts() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { ImmutableList<InventoryViewModel> inventoryViewModels = from(stockRepository.listEmergencyStockCards()).transform(stockCard -> InventoryViewModel.buildEmergencyModel(stockCard)).toList(); subscriber.onNext(inventoryViewModels); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "ProductPresenter.loadEmergencyProducts").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override void attachView(BaseView v); Observable<List<RegimeProductViewModel>> loadRegimeProducts(Regimen.RegimeType type); Observable<Regimen> saveRegimes(RegimeProductViewModel viewModel, final Regimen.RegimeType regimeType); Observable<List<InventoryViewModel>> loadEmergencyProducts();  }
@Test public void loadEmergencyProducts() throws Exception { StockCard stockCard = new StockCard(); stockCard.setProduct(new ProductBuilder().setPrimaryName("Product name").setCode("011111").build()); when(stockRepository.listEmergencyStockCards()).thenReturn(newArrayList(stockCard)); TestSubscriber<List<InventoryViewModel>> subscriber = new TestSubscriber<>(); presenter.loadEmergencyProducts().subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); assertThat(subscriber.getOnNextEvents().get(0).size(), is(1)); assertThat(subscriber.getOnNextEvents().get(0).get(0).getProductName(), is("Product name")); }