when(mockedMessage.getFrom()).thenReturn(sender);
when(sender.getMailbox()).thenReturn(address);
when(address.isSetEmailAddress()).thenReturn(true);
when(address.getEmailAddress()).thenReturn("seank@int.test");
MailboxItem mail = new ExchangeEmail(mockedMessage);
assertTrue(mail.hasKey("Sender"));
assertEquals("seank@int.test", mail.getHeader("Sender"));
mockedMessage = mock(MessageType.class);
sender = mock(SingleRecipientType.class);
address = mock(EmailAddressType.class);
when(mockedMessage.isSetFrom()).thenReturn(true);
when(mockedMessage.getFrom()).thenReturn(sender);
when(sender.getMailbox()).thenReturn(address);
when(address.isSetEmailAddress()).thenReturn(false);
mail = new ExchangeEmail(mockedMessage);
assertFalse(mail.hasKey("Sender"));
assertNull(mail.getHeader("Sender"));
mockedMessage = mock(MessageType.class);
sender = mock(SingleRecipientType.class);
address = mock(EmailAddressType.class);
when(mockedMessage.isSetFrom()).thenReturn(false);
when(mockedMessage.isSetSender()).thenReturn(true);
when(mockedMessage.getSender()).thenReturn(sender);
when(sender.getMailbox()).thenReturn(address);
when(address.isSetEmailAddress()).thenReturn(true);
when(address.getEmailAddress()).thenReturn("seank@int.test");
mail = new ExchangeEmail(mockedMessage);
assertTrue(mail.hasKey("Sender"));
assertEquals("seank@int.test", mail.getHeader("Sender"));
mockedMessage = mock(MessageType.class);
when(mockedMessage.isSetFrom()).thenReturn(false);
mail = new ExchangeEmail(mockedMessage);
assertFalse(mail.hasKey("Sender"));
assertNull(mail.getHeader("Sender"));
}