MailUserAccessEventHandler implements UserAccessEventHandler { String getTemplatePathAccessChanged(LocalDateTime newEndTime, LocalDateTime previousEndTime) { if(previousEndTime.isAfter(newEndTime)) { return "/templates/mail/UserAccessShortened.vm"; } else { return "/templates/mail/UserAccessExtended.vm"; } } 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 getTemplatePathAccessChangedReturnsPathForExtendedWhenNewAfterOld() { var expectedTemplatePath = "/templates/mail/UserAccessExtended.vm"; var oldEndTime = LocalDateTime.of(2019, 2, 3, 10, 0); var newEndTime = oldEndTime.plus(1L, ChronoUnit.HOURS); var actualTemplatePath = mailUserAccessEventHandler.getTemplatePathAccessChanged(newEndTime, oldEndTime); assertThat(actualTemplatePath).isEqualTo(expectedTemplatePath); }
@Test public void getTemplatePathAccessChangedReturnsPathForShortenedWhenOldAfterNew() { var expectedTemplatePath = "/templates/mail/UserAccessShortened.vm"; var oldEndTime = LocalDateTime.of(2019, 2, 3, 10, 0); var newEndTime = oldEndTime.minus(1L, ChronoUnit.HOURS); var actualTemplatePath = mailUserAccessEventHandler.getTemplatePathAccessChanged(newEndTime, oldEndTime); assertThat(actualTemplatePath).isEqualTo(expectedTemplatePath); }