@Test public void shouldLoadMasterProductsList() throws LMISException { StockCard stockCardVIA = StockCardBuilder.buildStockCard(); Product productVIA = new ProductBuilder().setPrimaryName("VIA Product").setCode("VIA Code").build(); stockCardVIA.setProduct(productVIA); StockCard stockCardMMIA = StockCardBuilder.buildStockCard(); Product productMMIA = new ProductBuilder().setProductId(10L).setPrimaryName("MMIA Product").setCode("MMIA Code").setIsArchived(true).build(); stockCardMMIA.setProduct(productMMIA); StockCard unknownAStockCard = StockCardBuilder.buildStockCard(); Product productUnknownA = new ProductBuilder().setPrimaryName("A Unknown Product").setCode("A Code").build(); unknownAStockCard.setProduct(productUnknownA); StockCard unknownBStockCard = StockCardBuilder.buildStockCard(); Product productUnknownB = new ProductBuilder().setPrimaryName("B Unknown Product").setCode("B Code").build(); unknownBStockCard.setProduct(productUnknownB); when(productRepositoryMock.listProductsArchivedOrNotInStockCard()).thenReturn(Arrays.asList(productMMIA, productVIA, productUnknownB, productUnknownA)); when(stockRepositoryMock.queryStockCardByProductId(10L)).thenReturn(stockCardMMIA); TestSubscriber<List<InventoryViewModel>> subscriber = new TestSubscriber<>(); Observable<List<InventoryViewModel>> observable = initialInventoryPresenter.loadInventory(); observable.subscribe(subscriber); subscriber.awaitTerminalEvent(); subscriber.assertNoErrors(); List<InventoryViewModel> receivedInventoryViewModels = subscriber.getOnNextEvents().get(0); assertEquals(4, receivedInventoryViewModels.size()); }
@Override public Observable<List<InventoryViewModel>> loadInventory() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> inventoryProducts = productRepository.listProductsArchivedOrNotInStockCard(); inventoryViewModelList.addAll(from(inventoryProducts) .transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventory").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }
InitialInventoryPresenter extends InventoryPresenter { @Override public Observable<List<InventoryViewModel>> loadInventory() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> inventoryProducts = productRepository.listProductsArchivedOrNotInStockCard(); inventoryViewModelList.addAll(from(inventoryProducts) .transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventory").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } }
InitialInventoryPresenter extends InventoryPresenter { @Override public Observable<List<InventoryViewModel>> loadInventory() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> inventoryProducts = productRepository.listProductsArchivedOrNotInStockCard(); inventoryViewModelList.addAll(from(inventoryProducts) .transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventory").reportToFabric(); subscriber.onError(e); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }  }
InitialInventoryPresenter extends InventoryPresenter { @Override public Observable<List<InventoryViewModel>> loadInventory() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> inventoryProducts = productRepository.listProductsArchivedOrNotInStockCard(); inventoryViewModelList.addAll(from(inventoryProducts) .transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventory").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); }
InitialInventoryPresenter extends InventoryPresenter { @Override public Observable<List<InventoryViewModel>> loadInventory() { return Observable.create((Observable.OnSubscribe<List<InventoryViewModel>>) subscriber -> { try { List<Product> inventoryProducts = productRepository.listProductsArchivedOrNotInStockCard(); inventoryViewModelList.addAll(from(inventoryProducts) .transform(product -> convertProductToStockCardViewModel(product)).toList()); subscriber.onNext(inventoryViewModelList); subscriber.onCompleted(); } catch (LMISException e) { new LMISException(e, "InitialInventoryPresenter.loadInventory").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; }