Skip to content

Commit

Permalink
#483: provide API to clear the list too (needed for junit tests as we…
Browse files Browse the repository at this point in the history
…ll) [skip ci]
  • Loading branch information
bbottema committed Dec 13, 2023
1 parent 5c02a43 commit e211abc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,13 @@ public interface EmailPopulatingBuilder {
@SuppressWarnings("unused")
EmailPopulatingBuilder clearRecipients();

/**
* Resets <em>overrideReceivers</em> to empty.
*
* @see #withOverrideReceivers(List)
*/
EmailPopulatingBuilder clearOverrideReceivers();

/**
* Resets base dir for embedded images to {@code null}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ public static boolean equalsEmail(final Email email1, final Email email2) {
if (!fieldIsEqual(email1.getSubject(), email2.getSubject(), "subject")) {
return false;
}

if (!isEqualRecipientList(email1.getRecipients(), email2.getRecipients())) {
return false;
}
if (!isEqualRecipientList(email1.getOverrideReceivers(), email2.getOverrideReceivers())) {
return false;
}
if (!email1.getEmbeddedImages().containsAll(email2.getEmbeddedImages()) || !email2.getEmbeddedImages().containsAll(email1.getEmbeddedImages())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,15 @@ public EmailPopulatingBuilder clearRecipients() {
return this;
}

/**
* @see EmailPopulatingBuilder#clearOverrideReceivers()
*/
@Override
public EmailPopulatingBuilder clearOverrideReceivers() {
this.overrideReceivers.clear();
return this;
}

/**
* @see EmailPopulatingBuilder#clearEmbeddedImageBaseDir()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ private Email assertSendingEmail(final EmailPopulatingBuilder originalEmailPopul
.withHeader("governanceOverrideTest1", "overridden", true)
.withHeader("governanceOverrideTest2", "also overridden", true);

// envelope-level receivers would have been lost in the received Message, so we need to compensate for that
originalEmailPopulatingBuilder.clearOverrideReceivers();

if (!skipChecksDueToSmime) { // reading a signed mail is different from building a new one
assertThat(receivedEmail).isEqualTo(originalEmailPopulatingBuilder.buildEmail());
} else {
Expand Down

0 comments on commit e211abc

Please sign in to comment.