### Question:
ProjectDeleteService { @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) public void deleteProject(String projectId) { auditLogService.log("triggers delete of project {}", logSanitizer.sanitize(projectId, 30)); assertion.isValidProjectId(projectId); Project project = projectRepository.findOrFailProject(projectId); ProjectMessage message = new ProjectMessage(); message.setProjectId(project.getId()); message.setProjectActionTriggeredBy(userContext.getUserId()); User owner = project.getOwner(); if (owner == null) { LOG.warn("No owner found for project {} while deleting", project.getId()); } else { message.setProjectOwnerEmailAddress(owner.getEmailAdress()); } for (User user : project.getUsers()) { message.addUserEmailAddress(user.getEmailAdress()); } transactionService.deleteWithAssociationsInOwnTransaction(projectId); informProjectDeleted(message); if (owner != null) { sendRefreshUserAuth(owner); } }  @UseCaseAdministratorDeleteProject(@Step(number = 2, name = "Service deletes projects.", next = { 3, 4, 5, 6, 7}, description = "The service will delete the project with dependencies and triggers asynchronous events")) void deleteProject(String projectId);  }### Answer:
@Test public void when_a_project_is_found_it_will_be_deleted() { Project project1 = new Project(); project1.id="project1"; when(projectRepository.findOrFailProject("project1")).thenReturn(project1); serviceToTest.deleteProject("project1"); verify(transactionService).deleteWithAssociationsInOwnTransaction(project1.getId()); }
@Test public void when_a_project_is_not_found_nothing_not_found_exception_will_forwarded() { expected.expect(NotFoundException.class); when(projectRepository.findOrFailProject("project1")).thenThrow(new NotFoundException()); serviceToTest.deleteProject("project1"); }
@Test public void when_a_project_is_found_2_events_will_be_triggered_first_project_deleted_second_owner_recalc() { ArgumentCaptor<DomainMessage> captorMessage = ArgumentCaptor.forClass(DomainMessage.class); Project project1 = new Project(); project1.id="project1"; User owner1 = mock(User.class); when(owner1.getName()).thenReturn("owner1"); project1.owner=owner1; when(projectRepository.findOrFailProject("project1")).thenReturn(project1); serviceToTest.deleteProject("project1"); verify(eventBusService,times(2)).sendAsynchron(captorMessage.capture()); List<DomainMessage> allMessages = captorMessage.getAllValues(); DomainMessage value1 = allMessages.get(0); assertEquals(MessageID.PROJECT_DELETED, value1.getMessageId()); assertEquals("project1", value1.get(MessageDataKeys.PROJECT_DELETE_DATA).getProjectId()); DomainMessage value2 = allMessages.get(1); assertEquals(MessageID.REQUEST_USER_ROLE_RECALCULATION, value2.getMessageId()); assertEquals("owner1", value2.get(MessageDataKeys.USER_ID_DATA).getUserId()); }