@Test public void shouldSaveStockCardAndStockMovementAndUpdateProductAsNotArchived() throws Exception { Product product1 = new ProductBuilder().setIsKit(false).setCode("p1").setPrimaryName("name1").setProductId(1L).setIsArchived(false).build(); when(stockRepository.queryStockCardByProductId(1L)).thenReturn(null); Product product2 = new ProductBuilder().setIsKit(false).setCode("p2").setPrimaryName("name2").setProductId(2L).setIsArchived(true).build(); StockCard stockCard = new StockCardBuilder().setProduct(product2).setStockOnHand(10L).setCreateDate(new Date()).build(); when(stockRepository.queryStockCardByProductId(2L)).thenReturn(stockCard); Product kit = new ProductBuilder().setIsKit(true).setProductId(3L).setCode("SD1112").setPrimaryName("primary name").build(); when(productRepository.getByCode(anyString())).thenReturn(kit); StockCard kitStockCard = new StockCardBuilder().setStockCardId(112).setStockOnHand(1000).setCreateDate(new Date()).setProduct(kit).build(); when(stockRepository.queryStockCardByProductId(3L)).thenReturn(kitStockCard); InventoryViewModel product1VM = new InventoryViewModelBuilder(product1).setChecked(true).setKitExpectQuantity(300).build(); product1VM.getNewLotMovementViewModelList().add(new LotMovementViewModelBuilder().setLotNumber("some lot").setExpiryDate("Feb 2022").setQuantity("200").build()); InventoryViewModel product2VM = new InventoryViewModelBuilder(product2).setChecked(true).setKitExpectQuantity(100).build(); product2VM.getNewLotMovementViewModelList().add(new LotMovementViewModelBuilder().setLotNumber("some lot").setExpiryDate("Feb 2022").setQuantity("100").build()); presenter.getInventoryViewModels().addAll(Arrays.asList(product1VM, product2VM)); presenter.kitCode = "SD1112"; TestSubscriber subscriber = new TestSubscriber(); Subscription subscription = presenter.saveUnpackProductsObservable(2, documentNumber, signature).subscribe(subscriber); presenter.subscriptions.add(subscription); subscriber.awaitTerminalEvent(); ArgumentCaptor<List> argument = ArgumentCaptor.forClass(List.class); verify(stockRepository).batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(argument.capture()); List<List> stockCardsArguments = argument.getAllValues(); assertEquals(200L, ((StockCard) stockCardsArguments.get(0).get(0)).getStockOnHand(), 0L); assertFalse(((StockCard) stockCardsArguments.get(0).get(0)).getStockMovementItemsWrapper().isEmpty()); assertEquals(110L, ((StockCard) stockCardsArguments.get(0).get(1)).getStockOnHand(), 0L); assertFalse(((StockCard) stockCardsArguments.get(0).get(1)).getProduct().isArchived()); assertFalse(((StockCard) stockCardsArguments.get(0).get(1)).getStockMovementItemsWrapper().isEmpty()); assertEquals(998L, ((StockCard) stockCardsArguments.get(0).get(2)).getStockOnHand(), 0L); }
public Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature) { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { List<StockCard> stockCards = new ArrayList<>(); Collection<StockCard> list = FluentIterable.from(inventoryViewModels) .filter(inventoryViewModel -> inventoryViewModel.getLotListQuantityTotalAmount() > 0) .transform(inventoryViewModel -> { try { return createStockCardForProductWithLot(inventoryViewModel, documentNumber, signature); } catch (LMISException e) { subscriber.onError(e); } return null; }).toList(); for (StockCard stockCard : list) { stockCards.add(stockCard); } stockCards.add(getStockCardForKit(kitUnpackQuantity, documentNumber, signature)); stockRepository.batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(stockCards); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException exception) { subscriber.onError(exception); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); }
UnpackKitPresenter extends Presenter { public Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature) { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { List<StockCard> stockCards = new ArrayList<>(); Collection<StockCard> list = FluentIterable.from(inventoryViewModels) .filter(inventoryViewModel -> inventoryViewModel.getLotListQuantityTotalAmount() > 0) .transform(inventoryViewModel -> { try { return createStockCardForProductWithLot(inventoryViewModel, documentNumber, signature); } catch (LMISException e) { subscriber.onError(e); } return null; }).toList(); for (StockCard stockCard : list) { stockCards.add(stockCard); } stockCards.add(getStockCardForKit(kitUnpackQuantity, documentNumber, signature)); stockRepository.batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(stockCards); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException exception) { subscriber.onError(exception); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } }
UnpackKitPresenter extends Presenter { public Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature) { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { List<StockCard> stockCards = new ArrayList<>(); Collection<StockCard> list = FluentIterable.from(inventoryViewModels) .filter(inventoryViewModel -> inventoryViewModel.getLotListQuantityTotalAmount() > 0) .transform(inventoryViewModel -> { try { return createStockCardForProductWithLot(inventoryViewModel, documentNumber, signature); } catch (LMISException e) { subscriber.onError(e); } return null; }).toList(); for (StockCard stockCard : list) { stockCards.add(stockCard); } stockCards.add(getStockCardForKit(kitUnpackQuantity, documentNumber, signature)); stockRepository.batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(stockCards); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException exception) { subscriber.onError(exception); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } UnpackKitPresenter(); }
UnpackKitPresenter extends Presenter { public Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature) { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { List<StockCard> stockCards = new ArrayList<>(); Collection<StockCard> list = FluentIterable.from(inventoryViewModels) .filter(inventoryViewModel -> inventoryViewModel.getLotListQuantityTotalAmount() > 0) .transform(inventoryViewModel -> { try { return createStockCardForProductWithLot(inventoryViewModel, documentNumber, signature); } catch (LMISException e) { subscriber.onError(e); } return null; }).toList(); for (StockCard stockCard : list) { stockCards.add(stockCard); } stockCards.add(getStockCardForKit(kitUnpackQuantity, documentNumber, signature)); stockRepository.batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(stockCards); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException exception) { subscriber.onError(exception); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } 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); }
UnpackKitPresenter extends Presenter { public Observable saveUnpackProductsObservable(final int kitUnpackQuantity, final String documentNumber, final String signature) { return Observable.create((Observable.OnSubscribe<Void>) subscriber -> { try { List<StockCard> stockCards = new ArrayList<>(); Collection<StockCard> list = FluentIterable.from(inventoryViewModels) .filter(inventoryViewModel -> inventoryViewModel.getLotListQuantityTotalAmount() > 0) .transform(inventoryViewModel -> { try { return createStockCardForProductWithLot(inventoryViewModel, documentNumber, signature); } catch (LMISException e) { subscriber.onError(e); } return null; }).toList(); for (StockCard stockCard : list) { stockCards.add(stockCard); } stockCards.add(getStockCardForKit(kitUnpackQuantity, documentNumber, signature)); stockRepository.batchSaveUnpackStockCardsWithMovementItemsAndUpdateProduct(stockCards); subscriber.onNext(null); subscriber.onCompleted(); } catch (LMISException exception) { subscriber.onError(exception); } }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()); } 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);  }