RepositoryApplicationService implements ApplicationService { @Transactional @Override public ProjectApplication deleteApplication(User user, long applicationId) throws ApplicationNotFoundException { var application = applicationRepo.findByUserAndId(user, applicationId).orElseThrow(ApplicationNotFoundException::new); applicationRepo.delete(application); log.debug(String.format("Application with id '%d' of user '%s' was deleted", applicationId, user.getId())); return application; } @Autowired  RepositoryApplicationService(ProjectService projectService,
                                        ProjectApplicationRepository applicationRepo,
                                        ProjectApplicationEventHandler applicationEventHandler,
                                        Clock clock,
                                        ProjectBoardConfigurationProperties properties); @Override boolean userHasAppliedForProject(User user, Project project); @Override @Transactional ProjectApplication createApplicationForUser(User user, String projectId, String comment); @Override List<ProjectApplication> getApplicationsOfUser(User user, Sort sort); @Override List<ProjectApplication> getApplicationsOfUsers(Collection<User> users, Sort sort); @Transactional @Override ProjectApplication deleteApplication(User user, long applicationId);  }
@Test public void deleteApplicationDeletesApplicationWhenPresent() { var applicationId = 1L; var application = new ProjectApplication(projectMock, "Comment", userMock, LocalDateTime.now(clock)); given(applicationRepoMock.findByUserAndId(userMock, applicationId)).willReturn(Optional.of(application)); var deletedApplication = applicationService.deleteApplication(userMock, applicationId); assertThat(deletedApplication).isEqualTo(application); verify(applicationRepoMock).delete(application); }
@Test public void deleteApplicationDeletesApplicationWhenApplicationNotFound() { var applicationId = 1L; given(applicationRepoMock.findByUserAndId(userMock, applicationId)).willReturn(Optional.empty()); assertThatThrownBy(() -> applicationService.deleteApplication(userMock, applicationId)) .isInstanceOf(ApplicationNotFoundException.class); }