java.lang.Object
ch.martinelli.oss.testcontainers.mailpit.assertions.MessageAwaiter

public class MessageAwaiter extends Object
Fluent builder for awaiting and asserting on messages.

Example usage:


 assertThat(mailpitContainer)
     .awaitMessage()
     .withSubject("Welcome")
     .from("noreply@example.com")
     .to("user@example.com")
     .isPresent();
 
  • Constructor Details

  • Method Details

    • withSubject

      public MessageAwaiter withSubject(String subject)
      Filters messages by exact subject match.
      Parameters:
      subject - the expected subject
      Returns:
      this awaiter
    • withSubjectContaining

      public MessageAwaiter withSubjectContaining(String substring)
      Filters messages by subject containing a substring.
      Parameters:
      substring - the substring to search for
      Returns:
      this awaiter
    • from

      public MessageAwaiter from(String senderAddress)
      Filters messages by sender address.
      Parameters:
      senderAddress - the expected sender email address
      Returns:
      this awaiter
    • to

      public MessageAwaiter to(String recipientAddress)
      Filters messages by recipient address.
      Parameters:
      recipientAddress - the expected recipient email address
      Returns:
      this awaiter
    • cc

      public MessageAwaiter cc(String ccAddress)
      Filters messages by CC recipient address.
      Parameters:
      ccAddress - the expected CC email address
      Returns:
      this awaiter
    • withAttachments

      public MessageAwaiter withAttachments()
      Filters messages that have attachments.
      Returns:
      this awaiter
    • withoutAttachments

      public MessageAwaiter withoutAttachments()
      Filters messages that have no attachments.
      Returns:
      this awaiter
    • matching

      public MessageAwaiter matching(Predicate<Message> customPredicate)
      Filters messages by a custom predicate.
      Parameters:
      customPredicate - the predicate to apply
      Returns:
      this awaiter
    • isPresent

      public MessageAssert isPresent()
      Waits for a matching message and returns assertions for it.
      Returns:
      MessageAssert for the found message
      Throws:
      org.awaitility.core.ConditionTimeoutException - if no matching message is found within the timeout
    • isAbsent

      public void isAbsent()
      Asserts that no matching message exists (does not wait).
      Throws:
      AssertionError - if a matching message is found