DirectSenderImpl extends DirectAdapter implements DirectSender { @Override public void sendOutboundDirect(MimeMessage message) { boolean failed = false; String errorMessage = null; getDirectEventLogger().log(DirectEventType.BEGIN_OUTBOUND_DIRECT, message); try { MimeMessage processedMessage = process(message).getProcessedMessage().getMessage(); getExternalMailSender().send(message.getAllRecipients(), processedMessage); } catch (Exception e) { failed = true; errorMessage = e.getLocalizedMessage(); LOG.error("Encounter sendOutBoundDirect error {}", errorMessage, e); return; } finally { LOG.debug("Before inserting Outgoing Message"); addOutgoingMessage(message, failed); } getDirectEventLogger().log(DirectEventType.END_OUTBOUND_DIRECT, message); } DirectSenderImpl(MailSender externalMailSender, DirectEventLogger directEventLogger); @Override void sendOutboundDirect(MimeMessage message); @Override void sendOutboundDirect(Address sender, Address[] recipients, DirectDocuments documents, String messageId);  }
@Test(expected = DirectException.class) public void testSendOutboundDirect_4args() { System.out.println("sendOutboundDirect"); Address sender = mock(Address.class); Address mockAddress1 = mock(Address.class); Set<Address> toAddresses = new HashSet<>(); toAddresses.add(mockAddress1); Address[] recipients = toAddresses.toArray(new Address[0]); DirectDocuments documents = mock(DirectDocuments.class); MimeMessageBuilder mockMMBuilder = mock(MimeMessageBuilder.class); String messageId = ""; when(mockMMBuilder.build()).thenReturn(mockMessage); oDirectSenderImpl.sendOutboundDirect(sender, recipients, documents, messageId); }