UserNotificationService { public void notifyCreatorOnComment(CommentEntity comment) { ProjectEntity project = comment.getProject(); if (comment.getUser().equals(project.getCreator())) { return; } final String projectLink = buildProjectLink(project.getId()); UserEntity recipient = project.getCreator(); StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariable("recipientName", recipient.getFullName()); context.setVariable("projectName", project.getTitle()); context.setVariable("commentingUser", comment.getUser().getFullName()); context.setVariable("commentExcerpt", commentExcerpt(comment)); context.setVariable("link", projectLink); final String mailContent = projectCommentedEmailTemplate.getValue(context, String.class); final SimpleMailMessage message = newMailMessage(recipient.getEmail(), SUBJECT_PROJECT_COMMENTED, mailContent); sendMails(Collections.singleton(message)); }  void sendActivationMail(UserEntity user); void sendPasswordRecoveryMail(UserEntity user); void notifyCreatorOnProjectStatusUpdate(ProjectEntity project); void notifyCreatorOnComment(CommentEntity comment); void notifyCreatorOnIdeaAccepted(IdeaEntity idea, String campaignTitle); void notifyCreatorOnIdeaRejected(IdeaEntity idea, String rejectionComment, String campaignTitle); void notifyCreatorAndAdminOnProjectModification(ProjectEntity project, UserEntity modifier); void notifyAdminOnProjectCreation(ProjectEntity project, String emailAddress); void notifyAdminOnIdeaCreation(IdeaEntity idea, String emailAddress, String campaignTitle); static final Integer COMMENT_EXCERPT_LENGTH; static final String FROM_ADDRESS; static final String PROJECT_LINK_PATTERN; static final String ACTIVATION_LINK_PATTERN; static final String PASSWORD_RECOVERY_LINK_PATTERN; static final String IDEA_CAMPAIGN_LINK_PATTERN; static final String IDEA_CAMPAIGN_LINK_ADMIN_PATTERN; static final String IDEA_CAMPAIGN_YOUR_IDEAS_LINK_PATTERN; static final String SUBJECT_ACTIVATION; static final String SUBJECT_PASSWORD_FORGOTTEN; static final String SUBJECT_IDEA_CREATED; static final String SUBJECT_IDEA_ACCEPTED; static final String SUBJECT_IDEA_REJECTED; static final String SUBJECT_PROJECT_MODIFIED; static final String SUBJECT_PROJECT_CREATED; static final String SUBJECT_PROJECT_PUBLISHED; static final String SUBJECT_PROJECT_REJECTED; static final String SUBJECT_PROJECT_DEFERRED; static final String SUBJECT_PROJECT_COMMENTED; }
@Test public void notifyCreatorOnComment_mailShouldContainAbridgedCommentAndItsCreatorName() { final UserEntity creator = aProjectCreator(); final UserEntity commentingUser = aUser("test_id_modifier"); final ProjectEntity project = project("proj3ctId", ProjectStatus.PUBLISHED, creator, "My Super Project"); final String projectLink = "https: final String testComment = aTestComment(UserNotificationService.COMMENT_EXCERPT_LENGTH + 5); final CommentEntity comment = new CommentEntity(project, commentingUser, testComment); final String expMessage = "Hallo %s,\n\n" + "zu Deinem Projekt \"%s\" wurde ein Kommentar von %s hinzugefügt:\n\n" + "\"%s\"\n\n" + "Zu Deinem Projekt:\n\n%s\n\n" + "Mit freundlichen Grüßen\n" + "Dein CrowdSource Team"; userNotificationService.notifyCreatorOnComment(comment); final SimpleMailMessage capturedMessage = getMessageFromMailSender(); assertThat(capturedMessage.getText(), is(String.format(expMessage, project.getCreator().getFullName(), project.getTitle(), commentingUser.getFullName(), testComment.substring(0, UserNotificationService.COMMENT_EXCERPT_LENGTH) + " ...", projectLink))); assertThat(capturedMessage.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(capturedMessage.getSubject(), is(UserNotificationService.SUBJECT_PROJECT_COMMENTED)); }
@Test public void notifyCreatorOnComment_commentingProjectCreatorDoesntReceiveMail() { final UserEntity creator = aProjectCreator(); final ProjectEntity project = project("proj3ctId", ProjectStatus.PUBLISHED, creator, "My Super Project"); final String projectLink = "https: final String testComment = aTestComment(UserNotificationService.COMMENT_EXCERPT_LENGTH + 5); final CommentEntity comment = new CommentEntity(project, creator, testComment); userNotificationService.notifyCreatorOnComment(comment); verify(javaMailSender, never()).send(isA(SimpleMailMessage.class)); }