DirectOutboundMsgHandler implements MessageHandler { @Override public boolean handleMessage(MimeMessage message) { boolean handled = false; try { directSender.sendOutboundDirect(message); handled = true; } catch (Exception e) { LOG.error("Exception while processing and sending outbound direct message", e); } return handled; } DirectOutboundMsgHandler(DirectSender directSender); @Override boolean handleMessage(MimeMessage message);  }
@Test public void canHandleOutboundMsg() throws MailClientException, MessagingException { mockSmtpAgent = mock(SmtpAgent.class); mockResult = DirectUnitTestUtil.getMockMessageProcessResult(1); directAdapter = mock(DirectAdapter.class); when(directAdapter.getSmtpAgent()).thenReturn(mockSmtpAgent); when(mockSmtpAgent.processMessage(any(MimeMessage.class), any(NHINDAddressCollection.class), any(NHINDAddress.class))).thenReturn(mockResult); mockExtMailSender = mock(MailSender.class); directSender = new DirectSenderImpl(mockExtMailSender, DirectEventLogger.getInstance()) { @Override protected void addOutgoingMessage(MimeMessage message, boolean failed) { } @Override protected SmtpAgent getSmtpAgent(URL url) { return mockSmtpAgent; } }; testOutboundMsgHandler = new DirectOutboundMsgHandler(directSender); MimeMessage mimeMessage = getSampleMimeMessage(); testOutboundMsgHandler.handleMessage(mimeMessage); verify(mockExtMailSender).send(any(Address[].class), any(MimeMessage.class)); }