UnpackKitPresenter extends Presenter { protected StockCard getStockCardForKit(int kitUnpackQuantity, String documentNumber, String signature) throws LMISException { Product kit = productRepository.getByCode(kitCode); StockCard kitStockCard = stockRepository.queryStockCardByProductId(kit.getId()); kitStockCard.setStockOnHand(kitStockCard.getStockOnHand() - kitUnpackQuantity); if (0 == kitStockCard.getStockOnHand()) { kitStockCard.setExpireDates(""); } StockMovementItem kitMovementItem = new StockMovementItem(kitStockCard); kitMovementItem.setReason(MovementReasonManager.UNPACK_KIT); kitMovementItem.setMovementType(MovementReasonManager.MovementType.ISSUE); kitMovementItem.setMovementQuantity(kitUnpackQuantity); kitMovementItem.setSignature(signature); kitMovementItem.setDocumentNumber(documentNumber); List<StockMovementItem> stockMovementItems = new ArrayList<>(); stockMovementItems.add(kitMovementItem); kitStockCard.setStockMovementItemsWrapper(stockMovementItems); return kitStockCard; } 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 shouldGetKitStockCardWithUnpackMovementItem() throws Exception { Product kit = new ProductBuilder().setIsKit(true).setProductId(888L) .setCode("SD1112").setPrimaryName("primary name").build(); StockCard kitStockCard = new StockCardBuilder().setStockCardId(112) .setStockOnHand(1000) .setCreateDate(new Date()) .setProduct(kit) .build(); presenter.kitCode = "SD1112"; when(productRepository.getByCode("SD1112")).thenReturn(kit); when(stockRepository.queryStockCardByProductId(888L)).thenReturn(kitStockCard); StockCard stockCardWithMovementItems = presenter.getStockCardForKit(1, documentNumber, signature); assertThat(stockCardWithMovementItems.getStockOnHand(), is(999L)); assertThat(stockCardWithMovementItems.getStockMovementItemsWrapper().size(), is(1)); assertThat(stockCardWithMovementItems.getStockMovementItemsWrapper().get(0).getMovementQuantity(), is(1L)); assertThat(stockCardWithMovementItems.getStockMovementItemsWrapper().get(0).getStockOnHand(), is(999L)); assertThat(stockCardWithMovementItems.getStockMovementItemsWrapper().get(0).getSignature(), is(signature)); assertThat(stockCardWithMovementItems.getStockMovementItemsWrapper().get(0).getDocumentNumber(), is(documentNumber)); }