DirectAdapterUtils { protected static Address getSender(Message message) throws MessagingException { Address[] fromAddresses = message.getFrom(); if (fromAddresses.length != 1) { throw new DirectException("Expected one from address, but encountered: " + fromAddresses.length); } return fromAddresses[0]; } private  DirectAdapterUtils(); static boolean isMdn(MessageEnvelope envelope);  }
@Test(expected = DirectException.class) public void willThrowDirectExceptionWhenMultipleFromsPresent() throws MessagingException { when(mockMessage.getFrom()).thenReturn(new Address[] { new InternetAddress("test@test1.com"), new InternetAddress("test@test2.com")}); DirectAdapterUtils.getSender(mockMessage); }
@Test(expected = DirectException.class) public void willThrowDirectExceptionWhenNoFromsPresent() throws MessagingException { when(mockMessage.getFrom()).thenReturn(EMPTY_ADDRESS_ARRAY); DirectAdapterUtils.getSender(mockMessage); }