InitialInventoryPresenter extends InventoryPresenter { void initOrArchiveBackStockCards() { defaultViewModelList.clear(); defaultViewModelList.addAll(inventoryViewModelList); for (InventoryViewModel inventoryViewModel : defaultViewModelList) { if (inventoryViewModel.isChecked()) { initOrArchiveBackStockCard(inventoryViewModel); } } }  @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 shouldInitStockCardAndCreateAInitInventoryMovementItem() throws LMISException { StockCard stockcard = new StockCard(); stockcard.setProduct(product); InventoryViewModel model = new InventoryViewModelBuilder(stockcard).setChecked(true).build(); InventoryViewModel model2 = new InventoryViewModelBuilder(product).setChecked(true).build(); model2.getNewLotMovementViewModelList().add(new LotMovementViewModelBuilder().setExpiryDate("Jan 2016").setQuantity("20").build()); model.getNewLotMovementViewModelList().add(new LotMovementViewModelBuilder().setExpiryDate("Feb 2015").setQuantity("2020").build()); model.getProduct().setArchived(true); initialInventoryPresenter.getInventoryViewModelList().add(model); initialInventoryPresenter.getInventoryViewModelList().add(model2); initialInventoryPresenter.getDefaultViewModelList().add(model); initialInventoryPresenter.getDefaultViewModelList().add(model2); initialInventoryPresenter.initOrArchiveBackStockCards(); verify(stockRepositoryMock, times(1)).updateStockCardWithProduct(any(StockCard.class)); verify(stockRepositoryMock, times(1)).addStockMovementAndUpdateStockCard(any(StockMovementItem.class)); }
@Test public void shouldReInventoryArchivedStockCard() throws LMISException { InventoryViewModel uncheckedModel = new InventoryViewModelBuilder(product) .setChecked(false) .build(); Product archivedProduct = new ProductBuilder().setPrimaryName("Archived product").setCode("BBC") .setIsArchived(true).build(); StockCard archivedStockCard = new StockCardBuilder().setStockOnHand(0).setProduct(archivedProduct).build(); InventoryViewModel archivedViewModel = new InventoryViewModelBuilder(archivedStockCard) .setChecked(true) .build(); List<InventoryViewModel> inventoryViewModelList = newArrayList(uncheckedModel, archivedViewModel); initialInventoryPresenter.getInventoryViewModelList().addAll(inventoryViewModelList); initialInventoryPresenter.getDefaultViewModelList().addAll(inventoryViewModelList); initialInventoryPresenter.initOrArchiveBackStockCards(); assertFalse(archivedStockCard.getProduct().isArchived()); verify(stockRepositoryMock, times(1)).updateStockCardWithProduct(archivedStockCard); }
@Test public void shouldInitStockCardAndCreateAInitInventoryMovementItemWithLot() throws Exception { product.setArchived(false); InventoryViewModel model = new InventoryViewModelBuilder(product).setChecked(true).build(); initialInventoryPresenter.getInventoryViewModelList().add(model); initialInventoryPresenter.getDefaultViewModelList().add(model); initialInventoryPresenter.initOrArchiveBackStockCards(); ArgumentCaptor<StockMovementItem> argument = ArgumentCaptor.forClass(StockMovementItem.class); verify(stockRepositoryMock).addStockMovementAndUpdateStockCard(argument.capture()); }