MailProjectApplicationEventHandler implements ProjectApplicationEventHandler { @Override public void onApplicationReceived(ProjectApplication application) { var applicant = application.getUser(); var manager = userService.getManagerOfUser(applicant); var applicantData = userService.getUserData(applicant); var managerData = userService.getUserData(manager); var issueLink = referralBaseUrl + application.getProject().getId(); var contextMap = Map.of( "projectApplication", application, "applicantData", applicantData, "managerData", managerData, "issueLink", issueLink ); var subjectTextPair = velocityMailTemplateService.getSubjectAndText("/templates/mail/UserAppliedForProject.vm", contextMap); var simpleMessage = new SimpleMessage(applicant, manager, subjectTextPair.getFirst(), subjectTextPair.getSecond()); mailSenderAdapter.queueMessage(simpleMessage); } MailProjectApplicationEventHandler(MailSenderAdapter mailSenderAdapter,
                                              UserService userService,
                                              VelocityMailTemplateService velocityMailTemplateService,
                                              MailConfigurationProperties mailConfigProperties); @Override void onApplicationReceived(ProjectApplication application);  }
@Test public void onApplicationReceivedQueuesExpectedMessage() { var projectId = "PB-2"; var expectedTemplatePath = "/templates/mail/UserAppliedForProject.vm"; var expectedSubject = "This is a subject :O"; var expectedText = "Cool text :)"; var subjectTextPair = new Pair<>(expectedSubject, expectedText); var expectedMessage = new SimpleMessage(applicantUserMock, managerUserMock, expectedSubject, expectedText); var jiraIssueLink = JIRA_ISSUE_URL + projectId; var expectedContextMap = Map.of( "projectApplication", projectApplicationMock, "applicantData", applicantDataMock, "managerData", managerDataMock, "issueLink", jiraIssueLink ); given(projectApplicationMock.getUser()).willReturn(applicantUserMock); given(projectApplicationMock.getProject()).willReturn(projectMock); given(projectMock.getId()).willReturn(projectId); given(userServiceMock.getManagerOfUser(applicantUserMock)).willReturn(managerUserMock); given(userServiceMock.getUserData(applicantUserMock)).willReturn(applicantDataMock); given(userServiceMock.getUserData(managerUserMock)).willReturn(managerDataMock); given(velocityMailTemplateServiceMock.getSubjectAndText(expectedTemplatePath, expectedContextMap)) .willReturn(subjectTextPair); mailProjectApplicationEventHandler.onApplicationReceived(projectApplicationMock); verify(mailSenderAdapterMock).queueMessage(expectedMessage); }