### Question:
MailServiceImpl implements MailService { @Override public void sendMail(String[] to, String subject, String text) { try { final SimpleMailMessage message = new SimpleMailMessage(); message.setTo(to); message.setSubject(subject); message.setText(text); emailSender.send(message); } catch (final MailException e) { log.error("Error sending mail", e); log.error("If you are using GMail check https: throw e; } }  @Override void sendMail(String[] to, String subject, String text); @Override void sendMail(String to, String subject, String text); @Override void sendMailWithTemplate(String[] to, String subject, SimpleMailMessage template, String... templateArgs); @Override void sendMailWithTemplate(String to, String subject, SimpleMailMessage template, String... templateArgs); @Override void sendHtmlMailWithFile(String[] to, String subject, String htmlText, String attachName, String attachment,
			boolean htmlenable); @Override void sendHtmlMailWithFile(String to, String subject, String text, String attachmentName, String attachment,
	        boolean htmlenable); @Autowired
	public JavaMailSender emailSender; }### Answer:
@Test public void testSendMailOK() { try { mailServiceImpl.sendMail(TEST_MAIL, "Subject","Text"); MimeMessage[] receivedMessages = server.getReceivedMessages(); assertEquals("", 1, receivedMessages.length); assertEquals("Text",GreenMailUtil.getBody(server.getReceivedMessages()[0])); assertTrue("OK testSendMailOK", true); } catch (final Exception e) { log.error("Error testSendMailOK", e); log.error("If you are using GMail check https: Assert.fail("Error sending mail"); } }
@Test public void testSendMailWithNoTo() { try { String to = null; mailServiceImpl.sendMail(to, "Subject","Text"); assertTrue("OK testSendMailWithNoTo", true); } catch (final Exception e) { log.error("Error testSendMailWithNoTo", e); log.error("If you are using GMail check https: Assert.assertTrue("You can´t send a mail without To",true); } }
@Test public void testSendMailArrayOK() { try { String[] to = new String[1]; to[0] = TEST_MAIL; mailServiceImpl.sendMail(to, "Subject","Text"); MimeMessage[] receivedMessages = server.getReceivedMessages(); assertEquals("", 1, receivedMessages.length); assertEquals("Text",GreenMailUtil.getBody(server.getReceivedMessages()[0])); assertTrue("OK testSendMailOK", true); } catch (final Exception e) { log.error("Error testSendMailOK", e); log.error("If you are using GMail check https: Assert.fail("Error sending mail"); } }