SyncDownManager { protected void updateDeactivateProductNotifyList(Product product) throws LMISException { Product existingProduct = productRepository.getByCode(product.getCode()); if (existingProduct == null) { return; } if (product.isActive() == existingProduct.isActive()) { return; } if (product.isActive()) { sharedPreferenceMgr.removeShowUpdateBannerTextWhenReactiveProduct(existingProduct.getPrimaryName()); return; } StockCard stockCard = stockRepository.queryStockCardByProductId(existingProduct.getId()); if (stockCard == null) { return; } if (stockCard.getProduct().isArchived()) { return; } if (stockCard.getStockOnHand() == 0) { sharedPreferenceMgr.setIsNeedShowProductsUpdateBanner(true, product.getPrimaryName()); } } SyncDownManager(); void syncDownServerData(Subscriber<SyncProgress> subscriber); void syncDownServerData(); void fetchKitChangeProduct(); Observable<Void> saveStockCardsFromLastYear(final List<StockCard> stockCards); Observable<Void> saveStockCards(final List<StockCard> stockCards, Scheduler scheduler);  }
@Test public void shouldUpdateNotifyBannerListWhenSOHIsZeroAndProductIsDeActive() throws Exception { Product product = new Product(); product.setPrimaryName("name"); product.setActive(false); product.setCode("code"); product.setArchived(false); Product existingProduct = ProductBuilder.create().setCode("code").setIsActive(true).setIsArchived(true).build(); when(productRepository.getByCode(product.getCode())).thenReturn(existingProduct); StockCard stockCard = new StockCard(); stockCard.setProduct(product); stockCard.setStockOnHand(0); when(stockRepository.queryStockCardByProductId(anyLong())).thenReturn(stockCard); syncDownManager.updateDeactivateProductNotifyList(product); verify(sharedPreferenceMgr).setIsNeedShowProductsUpdateBanner(true, "name"); }
@Test public void shouldNotUpdateNotifyBannerListWhenProductIsArchived() throws Exception { Product product = new Product(); product.setPrimaryName("name"); product.setActive(false); product.setCode("code"); product.setArchived(true); Product existingProduct = ProductBuilder.create().setCode("code").setIsActive(true).setIsArchived(true).build(); when(productRepository.getByCode(product.getCode())).thenReturn(existingProduct); StockCard stockCard = new StockCard(); stockCard.setProduct(product); stockCard.setStockOnHand(0); when(stockRepository.queryStockCardByProductId(anyLong())).thenReturn(stockCard); syncDownManager.updateDeactivateProductNotifyList(product); verify(sharedPreferenceMgr, never()).setIsNeedShowProductsUpdateBanner(true, "name"); }
@Test public void shouldRemoveNotifyBannerListWhenReactiveProduct() throws Exception { Product product = new Product(); product.setPrimaryName("new name"); product.setActive(true); product.setCode("code"); Product existingProduct = ProductBuilder.create().setCode("code").setIsActive(false).setPrimaryName("name").build(); when(productRepository.getByCode(product.getCode())).thenReturn(existingProduct); StockCard stockCard = new StockCard(); stockCard.setStockOnHand(0); when(stockRepository.queryStockCardByProductId(anyLong())).thenReturn(stockCard); syncDownManager.updateDeactivateProductNotifyList(product); verify(sharedPreferenceMgr).removeShowUpdateBannerTextWhenReactiveProduct("name"); }
@Test public void shouldNotUpdateBannerWhenExistingProductIsNull() throws Exception { Product product = new Product(); when(productRepository.getByCode(anyString())).thenReturn(null); syncDownManager.updateDeactivateProductNotifyList(product); verify(stockRepository, times(0)).queryStockCardByProductId(anyLong()); }