@Test public void shouldValidateProductBeforeSaveThrowExceptionIfPackSizeIsZero() throws Exception { Product spyProduct = spy(new Product()); doNothing().when(spyProduct).validate(); service.save(spyProduct); verify(spyProduct).validate(); }
@Transactional public void save(Product product) { product.validate(); ProductGroup productGroup = productGroupService.validateAndReturn(product.getProductGroup()); product.setProductGroup(productGroup); ProductForm productForm = productFormService.validateAndReturn(product.getForm()); product.setForm(productForm); DosageUnit dosageUnit = validateAndReturnDosageUnit(product.getDosageUnit()); product.setDosageUnit(dosageUnit); if (product.getId() == null) { repository.insert(product); return; } List<ProgramProduct> existingProgramProducts = programProductService.getByProductCode(product.getCode()); repository.update(product); notifyProgramCatalogChange(product, existingProgramProducts); }
ProductService { @Transactional public void save(Product product) { product.validate(); ProductGroup productGroup = productGroupService.validateAndReturn(product.getProductGroup()); product.setProductGroup(productGroup); ProductForm productForm = productFormService.validateAndReturn(product.getForm()); product.setForm(productForm); DosageUnit dosageUnit = validateAndReturnDosageUnit(product.getDosageUnit()); product.setDosageUnit(dosageUnit); if (product.getId() == null) { repository.insert(product); return; } List<ProgramProduct> existingProgramProducts = programProductService.getByProductCode(product.getCode()); repository.update(product); notifyProgramCatalogChange(product, existingProgramProducts); } }
ProductService { @Transactional public void save(Product product) { product.validate(); ProductGroup productGroup = productGroupService.validateAndReturn(product.getProductGroup()); product.setProductGroup(productGroup); ProductForm productForm = productFormService.validateAndReturn(product.getForm()); product.setForm(productForm); DosageUnit dosageUnit = validateAndReturnDosageUnit(product.getDosageUnit()); product.setDosageUnit(dosageUnit); if (product.getId() == null) { repository.insert(product); return; } List<ProgramProduct> existingProgramProducts = programProductService.getByProductCode(product.getCode()); repository.update(product); notifyProgramCatalogChange(product, existingProgramProducts); }  }
ProductService { @Transactional public void save(Product product) { product.validate(); ProductGroup productGroup = productGroupService.validateAndReturn(product.getProductGroup()); product.setProductGroup(productGroup); ProductForm productForm = productFormService.validateAndReturn(product.getForm()); product.setForm(productForm); DosageUnit dosageUnit = validateAndReturnDosageUnit(product.getDosageUnit()); product.setDosageUnit(dosageUnit); if (product.getId() == null) { repository.insert(product); return; } List<ProgramProduct> existingProgramProducts = programProductService.getByProductCode(product.getCode()); repository.update(product); notifyProgramCatalogChange(product, existingProgramProducts); }  @Transactional void save(Product product); Long getIdForCode(String code); Product getByCode(String code); boolean isActive(String code); Integer getTotalSearchResultCount(String searchParam); List<DosageUnit> getAllDosageUnits(); Product getById(Long id); }
ProductService { @Transactional public void save(Product product) { product.validate(); ProductGroup productGroup = productGroupService.validateAndReturn(product.getProductGroup()); product.setProductGroup(productGroup); ProductForm productForm = productFormService.validateAndReturn(product.getForm()); product.setForm(productForm); DosageUnit dosageUnit = validateAndReturnDosageUnit(product.getDosageUnit()); product.setDosageUnit(dosageUnit); if (product.getId() == null) { repository.insert(product); return; } List<ProgramProduct> existingProgramProducts = programProductService.getByProductCode(product.getCode()); repository.update(product); notifyProgramCatalogChange(product, existingProgramProducts); }  @Transactional void save(Product product); Long getIdForCode(String code); Product getByCode(String code); boolean isActive(String code); Integer getTotalSearchResultCount(String searchParam); List<DosageUnit> getAllDosageUnits(); Product getById(Long id);  }