MailUserAccessEventHandler implements UserAccessEventHandler { @Override public void onAccessCreated(User user, AccessInterval accessInterval) { var contextMap = getContextMap(user, accessInterval.getEndTime()); var subjectTextPair = velocityMailTemplateService.getSubjectAndText("/templates/mail/UserAccessCreated.vm", contextMap); var message = new TimeAwareMessage(user, user, subjectTextPair.getFirst(), subjectTextPair.getSecond(), accessInterval.getEndTime()); mailSenderAdapter.queueMessage(message); } MailUserAccessEventHandler(MailSenderAdapter mailSenderAdapter,
                                      UserService userService,
                                      VelocityMailTemplateService velocityMailTemplateService,
                                      ProjectBoardConfigurationProperties configurationProperties); @Override void onAccessCreated(User user, AccessInterval accessInterval); @Override void onAccessChanged(User user, AccessInterval accessInterval, LocalDateTime previousEndTime); @Override void onAccessRevoked(User user, LocalDateTime previousEndTime);  }
@Test public void onAccessCreatedQueuesExpectedMessage() { var expectedTemplatePath = "/templates/mail/UserAccessCreated.vm"; var expectedSubject = "Subject!"; var expectedText = "Text!"; var expectedEndTime = LocalDateTime.of(2019, 2, 3, 10, 0); var expectedContextMap = Map.of( "userData", userDataMock, "newDate", expectedEndTime.format(MailUserAccessEventHandler.DATE_TIME_FORMATTER), "projectBoardUrl", PROJECT_BOARD_URL ); var expectedMessage = new TimeAwareMessage(userMock, userMock, expectedSubject, expectedText, expectedEndTime); var subjectTextPair = new Pair<>(expectedSubject, expectedText); given(accessIntervalMock.getEndTime()).willReturn(expectedEndTime); given(userServiceMock.getUserData(userMock)).willReturn(userDataMock); given(velocityMailTemplateServiceMock.getSubjectAndText(expectedTemplatePath, expectedContextMap)) .willReturn(subjectTextPair); mailUserAccessEventHandler.onAccessCreated(userMock, accessIntervalMock); verify(mailSenderAdapterMock).queueMessage(expectedMessage); }