@Test public void shouldUpdateProductCategoryIfAlreadyExists() { ProductCategory productCategory = new ProductCategory(); productCategory.setId(1L); service.save(productCategory); verify(repository).update(productCategory); verify(repository, never()).insert(productCategory); }
public void save(ProductCategory productCategory) { if (productCategory.getId() != null) { repository.update(productCategory); return; } repository.insert(productCategory); }
ProductCategoryService { public void save(ProductCategory productCategory) { if (productCategory.getId() != null) { repository.update(productCategory); return; } repository.insert(productCategory); } }
ProductCategoryService { public void save(ProductCategory productCategory) { if (productCategory.getId() != null) { repository.update(productCategory); return; } repository.insert(productCategory); } @Autowired  ProductCategoryService(ProductCategoryRepository repository); }
ProductCategoryService { public void save(ProductCategory productCategory) { if (productCategory.getId() != null) { repository.update(productCategory); return; } repository.insert(productCategory); } @Autowired  ProductCategoryService(ProductCategoryRepository repository); Long getProductCategoryIdByCode(String code); ProductCategory getByCode(String code); void save(ProductCategory productCategory); ProductCategory getExisting(ProductCategory productCategory); ProductCategory getById(Long id); List<ProductCategory> getAll(); }
ProductCategoryService { public void save(ProductCategory productCategory) { if (productCategory.getId() != null) { repository.update(productCategory); return; } repository.insert(productCategory); } @Autowired  ProductCategoryService(ProductCategoryRepository repository); Long getProductCategoryIdByCode(String code); ProductCategory getByCode(String code); void save(ProductCategory productCategory); ProductCategory getExisting(ProductCategory productCategory); ProductCategory getById(Long id); List<ProductCategory> getAll();  }