### Question:
MailService { public void sendRemovingTopicMail(JCUser recipient, Topic topic, String curUser) { Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(USER, recipient); model.put(RECIPIENT_LOCALE, locale); model.put(CUR_USER, curUser); model.put(LINK_UNSUBSCRIBE, this.getDeploymentRootUrl() + "/branches/" + topic.getBranch().getId()); model.put(TOPIC, topic); try { String subjectTemplate = REMOVE_TOPIC_SUBJECT_TEMPLATE; String messageBodyTemplate = REMOVE_TOPIC_MESSAGE_BODY_TEMPLATE; if (topic.isCodeReview()) { subjectTemplate = REMOVE_CODE_REVIEW_SUBJECT_TEMPLATE; messageBodyTemplate = REMOVE_CODE_REVIEW_MESSAGE_BODY_TEMPLATE; } String subject = messageSource.getMessage(subjectTemplate, new Object[]{}, locale); this.sendEmail(recipient.getEmail(), subject, model, messageBodyTemplate); } catch (MailingFailedException e) { LOGGER.error("Failed to sent mail about removing topic or code review for user: " + recipient.getUsername()); } } MailService(JavaMailSender sender,
                       String from,
                       VelocityEngine engine,
                       MessageSource source,
                       JCommuneProperty notificationsEnabledProperty,
                       EscapeTool escapeTool,
                       EntityToDtoConverter converter); void sendPasswordRecoveryMail(JCUser user, String newPassword); void sendUpdatesOnSubscription(JCUser recipient, SubscriptionAwareEntity entity); void sendReceivedPrivateMessageNotification(JCUser recipient, PrivateMessage pm); void sendAccountActivationMail(JCUser recipient); void sendTopicMovedMail(
            JCUser recipient, Topic topic, String curUser, Class<T> subsсriptionTargetClass) ; void sendUserMentionedNotification(JCUser recipient, long postId); void sendRemovingTopicMail(JCUser recipient, Topic topic, String curUser); static final String REMOVE_TOPIC_SUBJECT_TEMPLATE; static final String REMOVE_CODE_REVIEW_SUBJECT_TEMPLATE; static final String REMOVE_TOPIC_MESSAGE_BODY_TEMPLATE; static final String REMOVE_CODE_REVIEW_MESSAGE_BODY_TEMPLATE; }### Answer:
@Test public void testSendRemovingTopicMailCurrentUserAware() throws Exception{ enableEmailNotifications(); service.sendRemovingTopicMail(user, topic, "admin"); this.checkMailCredentials(); String subjectTemplate = messageSource.getMessage("removeTopic.subject", new Object[]{}, user.getLanguage().getLocale()); String bodyTemplate = messageSource.getMessage("removeTopic.content", new Object[]{}, user.getLanguage().getLocale()); assertEquals(this.getMimeMailSubject(), subjectTemplate); assertTrue(this.getMimeMailBody().contains(bodyTemplate)); }
@Test public void removingTopicMailCurrentUserAwareShouldNotBeSentWhenForumNotificationsAreDisabled() throws Exception { disableEmailNotifications(); service.sendRemovingTopicMail(user, topic, "admin"); verify(sender, never()).send(any(MimeMessage.class)); }
@Test public void testSendRemovingTopicWithCodeReviewMailCurrentUserAware() throws Exception { enableEmailNotifications(); topic.setType(TopicTypeName.CODE_REVIEW.getName()); service.sendRemovingTopicMail(user, topic, "admin"); this.checkMailCredentials(); String subjectTemplate = messageSource.getMessage("removeCodeReview.subject", new Object[]{}, user.getLanguage().getLocale()); String bodyTemplate = messageSource.getMessage("removeCodeReview.content", new Object[]{}, user.getLanguage().getLocale()); assertEquals(this.getMimeMailSubject(), subjectTemplate); assertTrue(this.getMimeMailBody().contains(bodyTemplate)); }