### Question:
MailService { public void sendPasswordRecoveryMail(JCUser user, String newPassword) throws MailingFailedException { String urlSuffix = "/login"; String url = this.getDeploymentRootUrl() + urlSuffix; String name = user.getUsername(); Locale locale = user.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put(NAME, name); model.put("newPassword", newPassword); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(user.getEmail(), messageSource.getMessage("passwordRecovery.subject", new Object[]{}, locale), model, "passwordRecovery.vm"); LOGGER.info("Password recovery email sent for {}", name); } 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 testSendPasswordRecoveryMail() throws Exception { enableEmailNotifications(); service.sendPasswordRecoveryMail(user, PASSWORD); this.checkMailCredentials(); assertTrue(this.getMimeMailBody().contains(USERNAME)); assertTrue(this.getMimeMailBody().contains(PASSWORD)); assertTrue(this.getMimeMailBody().contains("http: }
@Test public void passwordRecoveryMailShouldNotBeSentIfNotificationsAreDisabled() throws Exception { disableEmailNotifications(); service.sendPasswordRecoveryMail(user, PASSWORD); verify(sender, never()).send(any(MimeMessage.class)); }
@Test(expectedExceptions = MailingFailedException.class) public void testRestorePasswordFail() throws NotFoundException, MailingFailedException { enableEmailNotifications(); Exception fail = new MailSendException(""); doThrow(fail).when(sender).send(Matchers.<MimeMessage>any()); service.sendPasswordRecoveryMail(user, PASSWORD); }