RecipientsUtils { public List<MailAddress> getRecipients(Mail originalMail) throws MessagingException { List<MailAddress> recipients = mailet.getRecipients(); if (!recipients.isEmpty()) { if (containsOnlyUnalteredOrRecipients(recipients)) { return ImmutableList.of(); } return SpecialAddressesUtils.from(mailet).replaceSpecialAddresses(originalMail, recipients); } return ImmutableList.of(); } private  RecipientsUtils(RedirectNotify mailet); static RecipientsUtils from(RedirectNotify mailet); List<MailAddress> getRecipients(Mail originalMail);  }
@Test public void getRecipientsShouldReturnEmptyWhenMailetRecipientsIsEmpty() throws Exception { when(mailet.getRecipients()) .thenReturn(ImmutableList.<MailAddress>of()); FakeMail fakeMail = FakeMail.defaultFakeMail(); List<MailAddress> recipients = testee.getRecipients(fakeMail); assertThat(recipients).isEmpty(); }
@Test public void getRecipientsShouldReturnEmptyWhenMailetRecipientsContainsOnlyUnaltered() throws Exception { when(mailet.getRecipients()) .thenReturn(ImmutableList.of(SpecialAddress.UNALTERED)); FakeMail fakeMail = FakeMail.defaultFakeMail(); List<MailAddress> recipients = testee.getRecipients(fakeMail); assertThat(recipients).isEmpty(); }
@Test public void getRecipientsShouldReturnEmptyWhenMailetRecipientsContainsOnlyRecipients() throws Exception { when(mailet.getRecipients()) .thenReturn(ImmutableList.of(SpecialAddress.RECIPIENTS)); FakeMail fakeMail = FakeMail.defaultFakeMail(); List<MailAddress> recipients = testee.getRecipients(fakeMail); assertThat(recipients).isEmpty(); }
@Test public void getRecipientsShouldReturnRecipientsWhenMailetRecipientsAreCommon() throws Exception { ImmutableList<MailAddress> expectedRecipients = ImmutableList.of(new MailAddress("test", "james.org"), new MailAddress("test2", "james.org")); when(mailet.getRecipients()) .thenReturn(expectedRecipients); FakeMail fakeMail = FakeMail.defaultFakeMail(); List<MailAddress> recipients = testee.getRecipients(fakeMail); assertThat(recipients).containsOnlyElementsOf(expectedRecipients); }
@Test public void getRecipientsShouldReturnAddressesFromOriginalMailWhenMailetRecipientsAreSpecialAddresses() throws Exception { when(mailet.getRecipients()) .thenReturn(ImmutableList.of(SpecialAddress.FROM, SpecialAddress.TO)); MailAddress from = new MailAddress("from", "james.org"); MailAddress to = new MailAddress("to", "james.org"); MailAddress to2 = new MailAddress("to2", "james.org"); FakeMail fakeMail = FakeMail.builder() .name("name") .sender(from) .recipients(to, to2) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder() .addToRecipient(to.asString(), to2.asString()) .addFrom(from.asString()) .build()) .build(); List<MailAddress> recipients = testee.getRecipients(fakeMail); ImmutableList<MailAddress> expectedRecipients = ImmutableList.of(from, to, to2); assertThat(recipients).containsOnlyElementsOf(expectedRecipients); }