### Question:
SpecificationServiceImpl implements SpecificationService { @Override public Specification findById(Long id) { log.info(LogMessage.IN_FIND_BY_ID, id); return specificationRepo .findById(id) .orElseThrow( () -> new NotFoundException(ErrorMessage.SPECIFICATION_VALUE_NOT_FOUND_BY_ID + id)); }  @Override Specification save(Specification specification); @Override Specification findById(Long id); @Override List<Specification> findAll(); @Override Long deleteById(Long id); @Override Specification findByName(String specificationName); @Override List<SpecificationNameDto> findAllSpecificationDto();  }### Answer:
@Test void findByIdTest() { Specification genericEntity = new Specification(); when(specificationRepo.findById(anyLong())).thenReturn(Optional.of(genericEntity)); Specification foundEntity = specificationService.findById(anyLong()); assertEquals(genericEntity, foundEntity); }
@Test void findByIdGivenIdNullThenThrowException() { assertThrows(NotFoundException.class, () -> { specificationService.findById(null); }); }