UserNotificationService { public void notifyAdminOnIdeaCreation(IdeaEntity idea, String emailAddress, String campaignTitle) { StandardEvaluationContext context = new StandardEvaluationContext(); context.setVariable("fullName", idea.getCreator().getFullName()); context.setVariable("ideaTitle", idea.getOriginalTitle()); context.setVariable("ideaPitch", idea.getOriginalPitch()); context.setVariable("link", buildIdeasCampaignAdminLink(idea.getCampaignId())); context.setVariable("campaignTitle", campaignTitle); final String mailSubject = MessageFormat.format(SUBJECT_IDEA_CREATED, campaignTitle); final String mailContent = ideaCreatedEmailTemplate.getValue(context, String.class); sendMail(emailAddress, mailSubject, mailContent); }  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 notifyAdminOnIdeaCreation_ShouldSendMailWithResolvedTemplate() { UserEntity user = aUser("123456789"); IdeaEntity newIdea = IdeaEntity.createIdeaEntity(new IdeaIn("SCHOKOLADE", "Schokolade für alle!"), "eatMoreChocolateCampaign", user); userNotificationService.notifyAdminOnIdeaCreation(newIdea, ADMIN_EMAIL, "Schokoladen Kampagne"); SimpleMailMessage mail = getMessageFromMailSender(); assertThat(mail.getFrom(), is(UserNotificationService.FROM_ADDRESS)); assertThat(mail.getTo(), arrayContaining(ADMIN_EMAIL)); assertThat(mail.getSubject(), is(MessageFormat.format(UserNotificationService.SUBJECT_IDEA_CREATED, "Schokoladen Kampagne"))); assertThat(replaceLineBreaksIfWindows(mail.getText()), is( "Hallo Admin,\n\n" + "es liegt eine neue Idee zur Freigabe vor:\n\n" + "Name: Karl Ranseier\n" + "Title: SCHOKOLADE\n" + "Pitch: Schokolade für alle!\n" + "Kampagne: Schokoladen Kampagne\n\n" + "https: "Mit freundlichen Grüßen\n" + "Dein CrowdSource Team\n")); }