### Question:
LocationServiceImpl implements LocationService { @Override public Location findById(Long id) { log.info(LogMessage.IN_FIND_BY_ID, id); return locationRepo .findById(id) .orElseThrow( () -> new NotFoundException(ErrorMessage.LOCATION_NOT_FOUND_BY_ID + id)); }  @Override List<Location> findAll(); @Override Location findById(Long id); @Override Location save(Location location); @Override Location update(Long id, Location location); @Override Long deleteById(Long id); @Override Optional<Location> findByLatAndLng(Double lat, Double lng);  }### Answer:
@Test public void findByIdTest() { Location genericEntity = new Location(); when(locationRepo.findById(anyLong())).thenReturn(Optional.of(genericEntity)); Location foundEntity = locationService.findById(anyLong()); assertEquals(genericEntity, foundEntity); }
@Test(expected = NotFoundException.class) public void findByIdGivenIdNullThenThrowException() { locationService.findById(null); }