@Test public void shouldGetProductCategoryIdByCode() { String categoryCode = "category code"; Long categoryId = 1L; when(repository.getIdByCode(categoryCode)).thenReturn(categoryId); Long productCategoryIdByCode = service.getProductCategoryIdByCode(categoryCode); verify(repository).getIdByCode(categoryCode); assertThat(productCategoryIdByCode, is(categoryId)); }
public Long getProductCategoryIdByCode(String code) { return repository.getIdByCode(code); }
ProductCategoryService { public Long getProductCategoryIdByCode(String code) { return repository.getIdByCode(code); } }
ProductCategoryService { public Long getProductCategoryIdByCode(String code) { return repository.getIdByCode(code); } @Autowired  ProductCategoryService(ProductCategoryRepository repository); }
ProductCategoryService { public Long getProductCategoryIdByCode(String code) { return repository.getIdByCode(code); } @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 Long getProductCategoryIdByCode(String code) { return repository.getIdByCode(code); } @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();  }