@Test public void shouldValidateProgramProductPriceBeforeSaving() throws Exception { expectException.expect(DataException.class); expectException.expectMessage("error-code"); ProgramProductPrice programProductPrice = mock(ProgramProductPrice.class); doThrow(new DataException("error-code")).when(programProductPrice).validate(); service.updateProgramProductPrice(programProductPrice); }
public void updateProgramProductPrice(ProgramProductPrice programProductPrice) { programProductPrice.validate(); ProgramProduct programProduct = programProductPrice.getProgramProduct(); ProgramProduct programProductWithId = programProductRepository.getByProgramAndProductCode(programProduct); if (programProductWithId == null) throw new DataException("programProduct.product.program.invalid"); programProduct.setId(programProductWithId.getId()); programProduct.setModifiedBy(programProductPrice.getModifiedBy()); programProduct.setModifiedDate(programProductPrice.getModifiedDate()); programProductRepository.updateCurrentPrice(programProduct); programProductRepository.updatePriceHistory(programProductPrice); }
ProgramProductService { public void updateProgramProductPrice(ProgramProductPrice programProductPrice) { programProductPrice.validate(); ProgramProduct programProduct = programProductPrice.getProgramProduct(); ProgramProduct programProductWithId = programProductRepository.getByProgramAndProductCode(programProduct); if (programProductWithId == null) throw new DataException("programProduct.product.program.invalid"); programProduct.setId(programProductWithId.getId()); programProduct.setModifiedBy(programProductPrice.getModifiedBy()); programProduct.setModifiedDate(programProductPrice.getModifiedDate()); programProductRepository.updateCurrentPrice(programProduct); programProductRepository.updatePriceHistory(programProductPrice); } }
ProgramProductService { public void updateProgramProductPrice(ProgramProductPrice programProductPrice) { programProductPrice.validate(); ProgramProduct programProduct = programProductPrice.getProgramProduct(); ProgramProduct programProductWithId = programProductRepository.getByProgramAndProductCode(programProduct); if (programProductWithId == null) throw new DataException("programProduct.product.program.invalid"); programProduct.setId(programProductWithId.getId()); programProduct.setModifiedBy(programProductPrice.getModifiedBy()); programProduct.setModifiedDate(programProductPrice.getModifiedDate()); programProductRepository.updateCurrentPrice(programProduct); programProductRepository.updatePriceHistory(programProductPrice); }  }
ProgramProductService { public void updateProgramProductPrice(ProgramProductPrice programProductPrice) { programProductPrice.validate(); ProgramProduct programProduct = programProductPrice.getProgramProduct(); ProgramProduct programProductWithId = programProductRepository.getByProgramAndProductCode(programProduct); if (programProductWithId == null) throw new DataException("programProduct.product.program.invalid"); programProduct.setId(programProductWithId.getId()); programProduct.setModifiedBy(programProductPrice.getModifiedBy()); programProduct.setModifiedDate(programProductPrice.getModifiedDate()); programProductRepository.updateCurrentPrice(programProduct); programProductRepository.updatePriceHistory(programProductPrice); }  Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateProgramProductPrice(ProgramProductPrice programProductPrice); void save(ProgramProduct programProduct); void saveAndLogPriceChange(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); List<ProgramProduct> getByProductCode(String productCode); List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> getActiveByProgram(Long programId); ProgramProduct getByProgramAndProductId(Long programId, Long productId); List<ProgramProduct> search(String searchParam, Pagination pagination, String column); List<ProgramProduct> getUnapprovedProgramProducts(Long facilityTypeId, Long programId); Integer getTotalSearchResultCount(String searchParam, String column); @Transactional void saveAll(List<ProgramProduct> programProducts, Product product); void insertISA(ProgramProductISA isa); void updateISA(ProgramProductISA isa); }
ProgramProductService { public void updateProgramProductPrice(ProgramProductPrice programProductPrice) { programProductPrice.validate(); ProgramProduct programProduct = programProductPrice.getProgramProduct(); ProgramProduct programProductWithId = programProductRepository.getByProgramAndProductCode(programProduct); if (programProductWithId == null) throw new DataException("programProduct.product.program.invalid"); programProduct.setId(programProductWithId.getId()); programProduct.setModifiedBy(programProductPrice.getModifiedBy()); programProduct.setModifiedDate(programProductPrice.getModifiedDate()); programProductRepository.updateCurrentPrice(programProduct); programProductRepository.updatePriceHistory(programProductPrice); }  Long getIdByProgramIdAndProductId(Long programId, Long productId); void updateProgramProductPrice(ProgramProductPrice programProductPrice); void save(ProgramProduct programProduct); void saveAndLogPriceChange(ProgramProduct programProduct); ProgramProduct getByProgramAndProductCode(ProgramProduct programProduct); ProgramProductPrice getProgramProductPrice(ProgramProduct programProduct); List<ProgramProduct> getByProgram(Program program); List<ProgramProduct> getByProductCode(String productCode); List<ProgramProduct> getProgramProductsBy(String programCode, String facilityTypeCode); List<ProgramProduct> getNonFullSupplyProductsForProgram(Program program); List<ProgramProduct> getActiveByProgram(Long programId); ProgramProduct getByProgramAndProductId(Long programId, Long productId); List<ProgramProduct> search(String searchParam, Pagination pagination, String column); List<ProgramProduct> getUnapprovedProgramProducts(Long facilityTypeId, Long programId); Integer getTotalSearchResultCount(String searchParam, String column); @Transactional void saveAll(List<ProgramProduct> programProducts, Product product); void insertISA(ProgramProductISA isa); void updateISA(ProgramProductISA isa);  }