MailService { public void sendActivationEmail(User user) { this.sendEmailFromTemplate(user, "activationEmail", "email.activation.title"); } MailService(Environment env,
                       JavaMailSender javaMailSender,
                       MessageSource messageSource,
                       SpringTemplateEngine templateEngine); void sendActivationEmail(User user); void sendCreationEmail(User user); void sendPasswordResetMail(User user);  }
@Test public void whenSendActivationEmail() throws MessagingException, IOException { User user = new User(); user.setLogin("testlogin"); user.setEmail("test@email.com"); user.setLangKey("en"); this.mailService.sendActivationEmail(user); verify(javaMailSender).send((MimeMessage) messageCaptor.capture()); MimeMessage message = (MimeMessage) messageCaptor.getValue(); assertEquals(message.getAllRecipients()[0].toString(), user.getEmail()); assertEquals(message.getFrom()[0].toString(), "localhost@localhost"); assertEquals(message.getDataHandler().getContentType(), "text/html;charset=UTF-8"); assertTrue(!message.getContent().toString().isEmpty()); }