### Question:
MailServiceImpl implements MailService { @Override public void sendEmail(final String recipient, final String subject, final String body) { sendHtmlTextEmail(getDefaultSender(), recipient, subject, body); }  @Override void sendEmail(final String recipient, final String subject, final String body); static boolean isValidEmail(final String email);  }### Answer:
@Test public final void shouldSendPlainTextEmail() throws Exception { ArgumentCaptor<MimeMessage> mailMessageCaptor = ArgumentCaptor.forClass(MimeMessage.class); mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); verify(mailSender, Mockito.times(1)).send(mailMessageCaptor.capture()); verify(mimeMessage).setFrom(new InternetAddress(DEFAULT_SENDER)); verify(mimeMessage).setRecipient(Message.RecipientType.TO, new InternetAddress(DEFAULT_RECIPIENT)); verify(mimeMessage).setSubject(DEFAULT_SUBJECT); verify(mimeMessage).setContent(DEFAULT_BODY, "text/html"); }
@Test(expected = MailConfigurationException.class) public final void shouldThrowExceptionIfDefaultSenderIsNull() throws Exception { setDefaultSender(null); mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = MailConfigurationException.class) public final void shouldThrowExceptionIfDefaultSenderIsEmpty() throws Exception { setDefaultSender(""); mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = MailConfigurationException.class) public final void shouldThrowExceptionIfDefaultSenderIsBlank() throws Exception { setDefaultSender(" "); mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = MailConfigurationException.class) public final void shouldThrowExceptionIfDefaultSenderIsNotValid() throws Exception { setDefaultSender("invalid"); mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = InvalidMailAddressException.class) public final void shouldThrowExceptionIfRecipientIsNull() throws Exception { mailServiceImpl.sendEmail(null, DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = InvalidMailAddressException.class) public final void shouldThrowExceptionIfRecipientIsEmpty() throws Exception { mailServiceImpl.sendEmail("", DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = InvalidMailAddressException.class) public final void shouldThrowExceptionIfRecipientIsBlank() throws Exception { mailServiceImpl.sendEmail(" ", DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = InvalidMailAddressException.class) public final void shouldThrowExceptionIfRecipientIsNotValid() throws Exception { mailServiceImpl.sendEmail("invalid", DEFAULT_SUBJECT, DEFAULT_BODY); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfSubjectIsNull() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, null, DEFAULT_BODY); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfSubjectIsEmpty() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, "", DEFAULT_BODY); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfSubjectIsBlank() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, " ", DEFAULT_BODY); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfBodyIsNull() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, null); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfBodyIsEmpty() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, ""); }
@Test(expected = IllegalArgumentException.class) public final void shouldThrowExceptionIfBodyIsBlank() throws Exception { mailServiceImpl.sendEmail(DEFAULT_RECIPIENT, DEFAULT_SUBJECT, " "); }