InitialInventoryPresenter extends InventoryPresenter { public Observable<List<InventoryViewModel>> loadInventoryWithBasicProducts() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> basicProducts = productRepository.listBasicProducts(); inventoryViewModelList.addAll( from(basicProducts).transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); defaultViewModelList = new ArrayList<>(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventoryWithBasicProducts").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  @Override Observable<List<InventoryViewModel>> loadInventory(); Observable<List<InventoryViewModel>> loadInventoryWithBasicProducts(); Observable<Object> initStockCardObservable(); void addNonBasicProductsToInventory(List<Product> nonBasicProducts); void filterViewModels(final String keyword); void removeNonBasicProductElement(InventoryViewModel model); static final String EMPTY_STRING; }
@Test public void shouldLoadBasicProductsForInventory() throws LMISException { Product basicProduct1 = ProductBuilder.create().setPrimaryName("product").setCode("P1").setIsBasic(true).build(); Product basicProduct2 = ProductBuilder.create().setPrimaryName("product").setCode("P2").setIsBasic(true).build(); when(productRepositoryMock.listBasicProducts()).thenReturn(Arrays.asList(basicProduct1, basicProduct2)); TestSubscriber<List<InventoryViewModel>> subscriber = new TestSubscriber<>(); Observable<List<InventoryViewModel>> observable = initialInventoryPresenter.loadInventoryWithBasicProducts(); observable.subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); List<InventoryViewModel> receivedInventoryViewModels = subscriber.getOnNextEvents().get(0); assertEquals(2, receivedInventoryViewModels.size()); }