SentByMailet extends GenericMatcher { @Override public Collection<MailAddress> match(Mail mail) { return AttributeUtils .getAttributeValueFromMail(mail, Mail.SENT_BY_MAILET_ATTRIBUTE.getName()) .map(any -> mail.getRecipients()) .orElse(ImmutableList.of()); }  @Override Collection<MailAddress> match(Mail mail);  }
@Test public void matchShouldReturnRecipientsWhenAuthUserAttributeIsPresent() throws Exception { MailAddress recipient = MailAddressFixture.ANY_AT_JAMES; FakeMail fakeMail = FakeMail.builder() .name("mail") .recipient(recipient) .attribute(Mail.SENT_BY_MAILET_ATTRIBUTE) .build(); Collection<MailAddress> results = testee.match(fakeMail); assertThat(results).containsOnly(recipient); }
@Test public void matchShouldReturnEmptyCollectionWhenAuthUserAttributeIsAbsent() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .recipients(MailAddressFixture.ANY_AT_JAMES) .build(); Collection<MailAddress> results = testee.match(fakeMail); assertThat(results).isEmpty(); }
@Test public void matchShouldReturnEmptyCollectionWhenAuthUserAttributeIsAbsentAndThereIsNoRecipient() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .recipients() .build(); Collection<MailAddress> results = testee.match(fakeMail); assertThat(results).isEmpty(); }
@Test public void matchShouldReturnEmptyCollectionWhenAuthUserAttributeIsPresentAndThereIsNoRecipient() throws Exception { FakeMail fakeMail = FakeMail.builder() .name("mail") .recipients() .attribute(Mail.SENT_BY_MAILET_ATTRIBUTE) .build(); Collection<MailAddress> results = testee.match(fakeMail); assertThat(results).isEmpty(); }