### Question:
MailSender { public void sendMessage(MailItem item) throws MessagingException { checkNotNull(item.getReceivers()); checkNotNull(item.getReceivers().get(0)); checkNotNull(item.getTitle()); checkNotNull(item.getBody()); Message msg = new MimeMessage(session); if (item.getSender() == null || item.getSender().length() == 0) { item.setSender(configuration.getProperties().get(configuration.getUsernameKey()).toString()); } InternetAddress from = new InternetAddress(item.getSender()); msg.setFrom(from); InternetAddress[] to = new InternetAddress[item.getReceivers().size()]; for (int i = 0; i < item.getReceivers().size(); i++) { to[i] = new InternetAddress(item.getReceivers().get(i)); } msg.setRecipients(Message.RecipientType.TO, to); msg.setSubject(item.getTitle()); MimeBodyPart body = new MimeBodyPart(); body.setContent(item.getBody(), "text/html; charset=UTF-8"); Multipart content = new MimeMultipart(); content.addBodyPart(body); if (item.getAttachments() != null && item.getAttachments().size() > 0) { for (DataSource attachment : item.getAttachments()) { BodyPart itemBodyPart = new MimeBodyPart(); itemBodyPart.setDataHandler(new DataHandler(attachment)); itemBodyPart.setFileName(attachment.getName()); content.addBodyPart(itemBodyPart); } } msg.setContent(content); msg.saveChanges(); Transport.send(msg); for (Map.Entry<String, String[]> entry : item.getHeaders().entrySet()) { String[] value = msg.getHeader(entry.getKey()); if (value != null) { entry.setValue(value); } } } MailSender(MailConfiguration configuration); MailConfiguration getConfiguration(); void sendMessage(MailItem item);  }### Answer:
@Test public void sendMail() { MailItem mailItem = new MailItem(); mailItem.setTitle("Title"); mailItem.setBody("body"); mailItem.setReceivers("receiver1", "receiver2"); mailItem.getAttachments().add(new FileDataSource("file1path")); mailItem.getAttachments().add(new FileDataSource("file2path")); try { mailSender.sendMessage(mailItem); } catch (AuthenticationFailedException | NullPointerException e) { assert true; } catch (MessagingException e) { assert false; } }