### Question:
CategoryServiceImpl implements CategoryService { @Override public Category findById(Long id) { log.info(LogMessage.IN_FIND_BY_ID, id); return categoryRepo .findById(id) .orElseThrow( () -> new NotFoundException(ErrorMessage.CATEGORY_NOT_FOUND_BY_ID + id)); }  @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 findByIdTest() { Category genericEntity = new Category(); when(categoryRepo.findById(anyLong())).thenReturn(Optional.of(genericEntity)); Category foundEntity = categoryService.findById(anyLong()); assertEquals(genericEntity, foundEntity); }
@Test(expected = NotFoundException.class) public void findByIdGivenIdNullThenThrowException() { categoryService.findById(null); }