CommonsmailHelperImpl implements CommonsmailHelper { @Override public void doPopulateMultipartMailWithContent(MultiPartEmail multiPartEmail, Mail mail) throws AddressException, EmailException { String charset = "utf-8"; if (mail.getCharset() != null) { charset = mail.getCharset(); } multiPartEmail.setCharset(charset); String subject = ""; if (mail.getSubject() != null) { subject = mail.getSubject(); } multiPartEmail.setSubject(subject); if (mail.getFrom() != null) { Tuple<String, String> from = createValidEmailFromString(mail.getFrom()); if (from.y != null) { multiPartEmail.setFrom(from.x, from.y); } else { multiPartEmail.setFrom(from.x); } } if (mail.getTos() != null) { if (!mail.getTos().isEmpty()) { List<Tuple<String, String>> emails = createListOfAddresses(mail.getTos()); for (Tuple<String, String> email : emails) { if (email.y != null) { multiPartEmail.addTo(email.x, email.y); } else { multiPartEmail.addTo(email.x); } } } } if (mail.getReplyTo() != null) { if (!mail.getReplyTo().isEmpty()) { List<Tuple<String, String>> emails = createListOfAddresses(mail.getReplyTo()); for (Tuple<String, String> email : emails) { multiPartEmail.addReplyTo(email.x, email.y); } } } if (mail.getCcs() != null) { if (!mail.getCcs().isEmpty()) { List<Tuple<String, String>> emails = createListOfAddresses(mail.getCcs()); for (Tuple<String, String> email : emails) { multiPartEmail.addCc(email.x, email.y); } } } if (mail.getBccs() != null) { if (!mail.getBccs().isEmpty()) { List<Tuple<String, String>> emails = createListOfAddresses(mail.getBccs()); for (Tuple<String, String> email : emails) { multiPartEmail.addBcc(email.x, email.y); } } } if (mail.getHeaders() != null) { multiPartEmail.setHeaders(mail.getHeaders()); } }  @Override MultiPartEmail createMultiPartEmailWithContent(Mail mail); @Override void doPopulateMultipartMailWithContent(MultiPartEmail multiPartEmail, Mail mail); @Override void doSetServerParameter(MultiPartEmail multiPartEmail, String smtpHost,
            Integer smtpPort, Boolean smtpSsl, Boolean smtpStartTLS, Boolean smtpStartTLSRequired,
            String smtpUser, String smtpPassword,
            Boolean smtpDebug); @Override List<Tuple<String, String>> createListOfAddresses(Collection<String> emails); @Override Tuple<String, String> createValidEmailFromString(String email);  }
@Test public void testDoPopulateMultipartMailWithContent() throws Exception { Mail mail = MailImplTestHelper.getMailImplWithDemoContent(); MultiPartEmail multiPartEmail = commonsmailHelper.createMultiPartEmailWithContent(mail); commonsmailHelper.doPopulateMultipartMailWithContent(multiPartEmail, mail); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc2@domain"))); assertEquals("subject", multiPartEmail.getSubject()); assertEquals(new InternetAddress("from1@domain"), multiPartEmail.getFromAddress()); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses()) .contains(new InternetAddress("replyTo1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getReplyToAddresses()) .contains(new InternetAddress("replyTo2@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses()) .contains(new InternetAddress("cc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getCcAddresses()) .contains(new InternetAddress("cc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getBccAddresses()) .contains(new InternetAddress("bcc2@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses()) .contains(new InternetAddress("to1@domain"))); assertTrue(doConvertAdressesToInternetAddressList(multiPartEmail.getToAddresses()) .contains(new InternetAddress("to2@domain"))); }