DirectAdapter { protected MessageProcessResult process(MimeMessage message) { MessageProcessResult result = processAsDirectMessage(message); MessageEnvelope envelope = result.getProcessedMessage(); if (envelope == null) { throw new DirectException("Result Message Envelope is null: " + getErrorNotificationMsgs(result), message); } return result; } DirectAdapter(MailSender externalMailSender, DirectEventLogger directEventLogger);   }
@SuppressWarnings("unchecked") @Test(expected = DirectException.class) public void testExceptionHandlingMessagingException() throws MessagingException { DirectAdapter instance = new DirectAdapter(extMailSender, mockSmtpAgent, null) { }; MimeMessage mockMessage = mock(MimeMessage.class); when(mockMessage.getRecipients(any(RecipientType.class))).thenReturn(getMockAddresses()); when(mockMessage.getFrom()).thenReturn(getMockAddresses()); when(mockSmtpAgent.processMessage(any(MimeMessage.class), any(NHINDAddressCollection.class), any(NHINDAddress.class))).thenThrow(MessagingException.class); instance.process(mockMessage); }
@SuppressWarnings("unchecked") @Test(expected = DirectException.class) public void testExceptionHandlingException() throws MessagingException { DirectAdapter instance = new DirectAdapter(extMailSender, mockSmtpAgent, null) { }; MimeMessage mockMessage = mock(MimeMessage.class); when(mockMessage.getRecipients(any(RecipientType.class))).thenReturn(getMockAddresses()); when(mockMessage.getFrom()).thenReturn(getMockAddresses()); when(mockSmtpAgent.processMessage(any(MimeMessage.class), any(NHINDAddressCollection.class), any(NHINDAddress.class))).thenThrow(Exception.class); instance.process(mockMessage); }