UnpackKitPresenter extends Presenter { @NonNull protected StockCard createStockCardForProductWithLot(InventoryViewModel inventoryViewModel, String documentNumber, String signature) throws LMISException { List<StockMovementItem> stockMovementItems = new ArrayList<>(); StockCard stockCard = stockRepository.queryStockCardByProductId(inventoryViewModel.getProductId()); if (stockCard == null) { stockCard = new StockCard(); stockCard.setProduct(inventoryViewModel.getProduct()); stockMovementItems.add(stockCard.generateInitialStockMovementItem()); } stockCard.getProduct().setArchived(false); List<LotMovementViewModel> totalLotMovementViewModelList = new ArrayList<>(); totalLotMovementViewModelList.addAll(FluentIterable.from(inventoryViewModel.getExistingLotMovementViewModelList()).filter(new Predicate<LotMovementViewModel>() { @Override public boolean apply(LotMovementViewModel lotMovementViewModel) { return lotMovementViewModel.quantityGreaterThanZero(); } }).toList()); totalLotMovementViewModelList.addAll(inventoryViewModel.getNewLotMovementViewModelList()); stockMovementItems.add(createUnpackMovementItemAndLotMovement(stockCard, documentNumber, signature, totalLotMovementViewModelList)); stockCard.setStockOnHand(stockMovementItems.get(stockMovementItems.size() - 1).getStockOnHand()); stockCard.setStockMovementItemsWrapper(stockMovementItems); return stockCard; } UnpackKitPresenter(); @Override void attachView(BaseView v); Observable<List<InventoryViewModel>> getKitProductsObservable(final String kitCode, final int kitNum); Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature);  }
@Test public void shouldCreateStockCardForProductWithLot() throws Exception { when(stockRepository.queryStockCardByProductId(200L)).thenReturn(null); LotMovementViewModel lot = new LotMovementViewModelBuilder() .setLotNumber("test") .setLotSOH("100") .setMovementType(MovementReasonManager.MovementType.RECEIVE) .setExpiryDate("Aug 2016") .setQuantity("100") .build(); viewModel.setNewLotMovementViewModelList(newArrayList(lot, lot)); StockCard stockCard = presenter.createStockCardForProductWithLot(viewModel, documentNumber, signature); List<StockMovementItem> movementItems = stockCard.getStockMovementItemsWrapper(); assertThat(stockCard.getStockOnHand(), is(200L)); assertThat(movementItems.size(), is(2)); assertThat(movementItems.get(0).getStockOnHand(), is(0L)); assertNull(movementItems.get(0).getSignature()); assertThat(movementItems.get(1).getStockOnHand(), is(200L)); assertThat(movementItems.get(1).getSignature(), is(signature)); assertThat(movementItems.get(1).getDocumentNumber(), is(documentNumber)); assertThat(movementItems.get(1).getLotMovementItemListWrapper().size(), is(2)); assertThat(movementItems.get(1).getLotMovementItemListWrapper().get(0).getMovementQuantity(), is(100L)); assertThat(movementItems.get(1).getLotMovementItemListWrapper().get(0).getLot().getLotNumber(), is("test")); }