@Test(expected = InvalidMailAddressException.class) public final void shouldThrowExceptionIfSenderIsNotValid() throws Exception { mailServiceImpl.sendHtmlTextEmail("invalid", DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); }
protected void sendHtmlTextEmail(final String sender, final String recipient, final String subject, final String body) { validateEmail(sender); validateEmail(recipient); Preconditions.checkArgument(StringUtils.isNotBlank(subject), "e-mail subject should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(body), "e-mail body should not be blank"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { mimeMessageHelper.setFrom(sender); mimeMessageHelper.setTo(recipient); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(body, true); } catch (MessagingException e) { throw new MailPreparationException(e); } mailSender.send(mimeMessage); }
MailServiceImpl implements MailService { protected void sendHtmlTextEmail(final String sender, final String recipient, final String subject, final String body) { validateEmail(sender); validateEmail(recipient); Preconditions.checkArgument(StringUtils.isNotBlank(subject), "e-mail subject should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(body), "e-mail body should not be blank"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { mimeMessageHelper.setFrom(sender); mimeMessageHelper.setTo(recipient); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(body, true); } catch (MessagingException e) { throw new MailPreparationException(e); } mailSender.send(mimeMessage); } }
MailServiceImpl implements MailService { protected void sendHtmlTextEmail(final String sender, final String recipient, final String subject, final String body) { validateEmail(sender); validateEmail(recipient); Preconditions.checkArgument(StringUtils.isNotBlank(subject), "e-mail subject should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(body), "e-mail body should not be blank"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { mimeMessageHelper.setFrom(sender); mimeMessageHelper.setTo(recipient); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(body, true); } catch (MessagingException e) { throw new MailPreparationException(e); } mailSender.send(mimeMessage); }  }
MailServiceImpl implements MailService { protected void sendHtmlTextEmail(final String sender, final String recipient, final String subject, final String body) { validateEmail(sender); validateEmail(recipient); Preconditions.checkArgument(StringUtils.isNotBlank(subject), "e-mail subject should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(body), "e-mail body should not be blank"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { mimeMessageHelper.setFrom(sender); mimeMessageHelper.setTo(recipient); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(body, true); } catch (MessagingException e) { throw new MailPreparationException(e); } mailSender.send(mimeMessage); }  @Override void sendEmail(final String recipient, final String subject, final String body); static boolean isValidEmail(final String email); }
MailServiceImpl implements MailService { protected void sendHtmlTextEmail(final String sender, final String recipient, final String subject, final String body) { validateEmail(sender); validateEmail(recipient); Preconditions.checkArgument(StringUtils.isNotBlank(subject), "e-mail subject should not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(body), "e-mail body should not be blank"); MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage); try { mimeMessageHelper.setFrom(sender); mimeMessageHelper.setTo(recipient); mimeMessageHelper.setSubject(subject); mimeMessageHelper.setText(body, true); } catch (MessagingException e) { throw new MailPreparationException(e); } mailSender.send(mimeMessage); }  @Override void sendEmail(final String recipient, final String subject, final String body); static boolean isValidEmail(final String email);  }