### Question:
CategoryServiceImpl implements CategoryService { @Override public Category findByName(String name) { Category category = categoryRepo.findByName(name); if (category == null) { throw new NotFoundException(ErrorMessage.CATEGORY_NOT_FOUND_BY_NAME + name); } return categoryRepo.findByName(name); }  @Override Category save(CategoryDto dto); @Override Category save(Category category); @Override List<Category> findAll(); @Override Category findById(Long id); @Override Category update(Long id, Category category); @Override Long deleteById(Long id); @Override Category findByName(String name); @Override List<CategoryDto> findAllCategoryDto();  }### Answer:
@Test public void findByNameTest() { Category genericEntity = new Category(); when(categoryRepo.findByName(any())).thenReturn(genericEntity); Category foundEntity = categoryService.findByName(any()); assertEquals(genericEntity, foundEntity); }
@Test(expected = NotFoundException.class) public void findByNameWhenCategoryNullTest() { when(categoryRepo.findByName(anyString())).thenReturn(null); categoryService.findByName(anyString()); }