BulkInitialInventoryPresenter extends InventoryPresenter { protected void restoreDraftInventory() throws LMISException { List<DraftInitialInventory> draftInventoryList = inventoryRepository.queryAllInitialDraft(); List<BulkInitialInventoryViewModel> nonBasicLists = new ArrayList<>(); List<DraftInitialInventory> noBasicDraftInventoryList = new ArrayList<>(); for (DraftInitialInventory draftInventory : draftInventoryList) { for (InventoryViewModel viewModel : defaultViewModelList) { if ((viewModel.getProductId() == draftInventory.getProduct().getId())) { ((BulkInitialInventoryViewModel) viewModel).setInitialDraftInventory(draftInventory); } } if (!draftInventory.getProduct().isBasic()) { noBasicDraftInventoryList.add(draftInventory); } } for (DraftInitialInventory draftInventory : noBasicDraftInventoryList) { BulkInitialInventoryViewModel bulkInitialInventoryViewModel = new BulkInitialInventoryViewModel(draftInventory.getProduct()); bulkInitialInventoryViewModel.setInitialDraftInventory(draftInventory); bulkInitialInventoryViewModel.setViewType(BulkInitialInventoryAdapter.ITEM_NO_BASIC); nonBasicLists.add(bulkInitialInventoryViewModel); } if (nonBasicLists.size() >= 1) { buildNonBasicProductModels(nonBasicLists); } }  @Override Observable<List<InventoryViewModel>> loadInventory(); void addNonBasicProductsToInventory(List<Product> nonBasicProducts); List<String> getAllAddedNonBasicProduct(); void removeNonBasicProductElement(InventoryViewModel inventoryViewModel); Observable<Object> saveDraftInventoryObservable(); Observable<Object> doInventory();  }
@Test public void shouldRestoreDraftInventoryWithDraftLotItems() throws Exception { ArrayList<InventoryViewModel> inventoryViewModels = getStockCardViewModels(); ArrayList<DraftInitialInventory> draftInitialInventories = new ArrayList<>(); DraftInitialInventory draftInitialInventory = new DraftInitialInventory(); Product product = ProductBuilder.create().setProductId(1L).setCode("basicCode").setIsBasic(true).setPrimaryName("basicName").build(); StockCard stockCard = buildDefaultStockCard(); stockCard.setStockOnHand(107); draftInitialInventory.setProduct(product); draftInitialInventory.setQuantity(107L); LotMovementViewModel lotMovementViewModel1 = new LotMovementViewModelBuilder().setLotNumber("test").setExpiryDate("Sep 2016").setQuantity("110").build(); LotMovementViewModel lotMovementViewModel2 = new LotMovementViewModelBuilder().setLotNumber("testNew").setExpiryDate("Sep 2016").setQuantity("10").build(); inventoryViewModels.get(0).setExistingLotMovementViewModelList(newArrayList(lotMovementViewModel1)); DraftInitialInventoryLotItem draftInitialInventoryLotItem1 = new DraftInitialInventoryLotItem(lotMovementViewModel1,product); DraftInitialInventoryLotItem draftInitialInventoryLotItem2 = new DraftInitialInventoryLotItem(lotMovementViewModel2,product); draftInitialInventory.setDraftLotItemListWrapper(newArrayList(draftInitialInventoryLotItem1, draftInitialInventoryLotItem2)); draftInitialInventories.add(draftInitialInventory); when(mockInventoryRepository.queryAllInitialDraft()).thenReturn(draftInitialInventories); bulkInitialInventoryPresenter.getInventoryViewModelList().addAll(inventoryViewModels); bulkInitialInventoryPresenter.restoreDraftInventory(); assertThat(inventoryViewModels.get(0).getNewLotMovementViewModelList().size(), is(0)); assertThat(inventoryViewModels.get(0).getExistingLotMovementViewModelList().get(0).getLotNumber(), is("test")); }