AddDeliveredToHeader extends GenericMailet { @Override public void service(Mail mail) throws MessagingException { for (MailAddress recipient: mail.getRecipients()) { mail.addSpecificHeaderForRecipient(PerRecipientHeaders.Header.builder() .name(DELIVERED_TO) .value(recipient.asString()) .build(), recipient); } }  @Override void service(Mail mail); static final String DELIVERED_TO; }
@Test public void serviceShouldHandleMailWithoutRecipient() throws Exception { FakeMail mail = FakeMail.builder().name("mail").build(); testee.service(mail); assertThat(mail.getPerRecipientSpecificHeaders()) .isEqualTo(new PerRecipientHeaders()); }
@Test public void serviceShouldAddPerRecipientDeliveredToSpecificHeader() throws Exception { FakeMail mail = FakeMail.builder() .name("mail") .recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES) .build(); testee.service(mail); PerRecipientHeaders expectedResult = new PerRecipientHeaders() .addHeaderForRecipient( PerRecipientHeaders.Header.builder() .name(AddDeliveredToHeader.DELIVERED_TO) .value(MailAddressFixture.ANY_AT_JAMES.asString()) .build(), MailAddressFixture.ANY_AT_JAMES) .addHeaderForRecipient( PerRecipientHeaders.Header.builder() .name(AddDeliveredToHeader.DELIVERED_TO) .value(MailAddressFixture.OTHER_AT_JAMES.asString()) .build(), MailAddressFixture.OTHER_AT_JAMES); assertThat(mail.getPerRecipientSpecificHeaders()) .isEqualTo(expectedResult); }