### Question:
FunctionalityService { public void delete(Long projectId, Long id) throws BadRequestException { if (id == null) { throw new BadRequestException(Messages.PARAMETER_IS_MISSING, Entities.FUNCTIONALITY, "delete_functionality_missing_id_parameter"); } Functionality entity = repository.findByProjectIdAndId(projectId, id) .orElseThrow(() -> new NotFoundException(Messages.NOT_FOUND_FUNCTIONALITY_OR_FOLDER, Entities.FUNCTIONALITY)); repository.delete(entity); }  @Transactional(readOnly = true) List<FunctionalityWithChildrenDTO> findAllAsTree(long projectId); FunctionalityDTO update(long projectId, FunctionalityDTO dtoToUpdate); FunctionalityDTO create(Long projectId, NewFunctionalityDTO newDto); void delete(Long projectId, Long id); List<FunctionalityWithChildrenDTO> deleteList(Long projectId, List<Long> ids); FunctionalityDTO move(long projectId, MoveFunctionalityDTO moveRequest); List<FunctionalityWithChildrenDTO> moveList(long projectId, MoveFunctionalitiesDTO moveRequest); List<ScenarioDTO> findScenarios(long projectId, long functionalityId); List<ExporterInfoDTO> listAvailableExporters(); ByteArrayResource generateExport(List<Long> functionalitiesIds, String exportType, Map<String, String> requiredInfos); void importJSONFunctionalities(String projectCode, String jsonFunctionalities);  }### Answer:
@Test(expected = BadRequestException.class) public void delete_throwBadRequestException_whenIdIsNull() throws BadRequestException { Long projectId = 1L; functionalityService.delete(projectId, null); verify(repository, never()).delete(any()); }
@Test(expected = NotFoundException.class) public void delete_throwNotFoundException_whenIdIsUnknown() throws BadRequestException { Long projectId = 1L; Long id = 10L; when(repository.findByProjectIdAndId(projectId, id)).thenReturn(Optional.empty()); functionalityService.delete(projectId, id); verify(repository, never()).delete(any()); }
@Test public void delete_deleteFunctionality_whenIdExists() throws BadRequestException { Long projectId = 1L; Long id = 10L; Functionality functionality = mock(Functionality.class); when(repository.findByProjectIdAndId(projectId, id)).thenReturn(Optional.of(functionality)); functionalityService.delete(projectId, id); verify(repository).delete(functionality); }