### Question:
MailService { public void sendReceivedPrivateMessageNotification(JCUser recipient, PrivateMessage pm) { try { String urlSuffix = "/pm/inbox/" + pm.getId(); String url = this.getDeploymentRootUrl() + urlSuffix; Locale locale = recipient.getLanguage().getLocale(); Map<String, Object> model = new HashMap<>(); model.put("recipient", recipient); model.put(LINK, url); model.put(LINK_LABEL, getDeploymentRootUrlWithoutPort() + urlSuffix); model.put(RECIPIENT_LOCALE, locale); this.sendEmail(recipient.getEmail(), messageSource.getMessage("receivedPrivateMessageNotification.subject", new Object[]{}, locale), model, "receivedPrivateMessageNotification.vm"); } catch (MailingFailedException e) { LOGGER.error(String.format(LOG_TEMPLATE, "Private message", pm.getId(), 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 testSendReceivedPrivateMessageNotification() throws Exception { enableEmailNotifications(); PrivateMessage message = new PrivateMessage(null, null, "title", "body"); message.setId(1); service.sendReceivedPrivateMessageNotification(user, message); this.checkMailCredentials(); System.out.println(this.getMimeMailBody()); assertTrue(this.getMimeMailBody().contains("http: }
@Test public void receivedPrivateMessageNotificationShouldNotBeSentIfNotificationsAreDisabled() throws Exception { disableEmailNotifications(); PrivateMessage message = new PrivateMessage(null, null, "title", "body"); message.setId(1); service.sendReceivedPrivateMessageNotification(user, message); verify(sender, never()).send(any(MimeMessage.class)); }
@Test public void testSendReceivedPrivateMessageNotificationFail() { enableEmailNotifications(); Exception fail = new MailSendException(""); doThrow(fail).when(sender).send(Matchers.<SimpleMailMessage>any()); service.sendReceivedPrivateMessageNotification(user, new PrivateMessage(null, null, null, null)); }