AssertJ Mail is an extension library for the AssertJ assertion library.
It provides assertions for types from the javax.mail
and jakarta.mail
packages.
The hamcrest-mail sister project provides a set of Hamcrest matchers with similar features.
To use AssertJ Mail in a Maven project add a dependency on org.devopsix:assertj-mail
(for Java EE 8 / javax.mail) or
org.devopsix:assertj-mail-jakarta
(for Jakarta EE 9+ / jakarta.mail) to the pom.xml file.
<!-- Maven coordinates for Java EE 8 / javax.mail -->
<dependency>
<groupId>org.devopsix</groupId>
<artifactId>assertj-mail</artifactId>
<version>1.0.7</version>
<scope>test</scope>
</dependency>
<!-- Maven coordinates for Jakarta EE 9+ / jakarta.mail -->
<dependency>
<groupId>org.devopsix</groupId>
<artifactId>assertj-mail-jakarta</artifactId>
<version>1.0.7</version>
<scope>test</scope>
</dependency>
The assertions are available as static methods on the MailAssertions
class.
Here are a few examples:
Message message;
MailAssertions.assertThat(message).from()
.singleElement(as(MailAssertions.INTERNET_ADDRESS))
.address().isEqualTo("[email protected]");
MailAssertions.assertThat(message).to()
.singleElement(Assertions.as(MailAssertions.INTERNET_ADDRESS))
.address().isEqualTo("[email protected]");
MailAssertions.assertThat(message).subject().isEqualTo("Foo");
MailAssertions.assertThat(message).headerValue("Message-ID").isEqualTo("Foo");
MailAssertions.assertThat(message).dateHeaderValue("Resent-Date").isEqualToIgnoringNanos(date);
More example can be found in the examples directory (for Java EE 8 / javax.mail) and in the examples-jakarta directory (for Jakarta EE 9+ / jakarta.mail).
MessageAssert.headerValue(String name)
- An assertion for a message's header (String value)MessageAssert.headerValues(String name)
- An assertion for a message's header (multiple Strings values)MessageAssert.dateHeaderValue(String name)
- An assertion for a message's header (date value)MessageAssert.dateHeaderValues(String name)
- An assertion for a message's header (multiple date values)MessageAssert.textContent()
- An assertion for a message's text contentMessageAssert.binaryContent()
- An assertion for a message's binary contentMessageAssert.isMultipart()
- Asserts that a message has multipart contentMessageAssert.multipartContent()
- An assertion for a message's multipart contentMessageAssert.multipartContents()
- An assertion for a message's multipart contents (recursive)MessageAssert.date()
- An assertion for a message's “Date” headerMessageAssert.from()
- An assertion for a message's “From” headerMessageAssert.sender()
- An assertion for a message's “Sender” headerMessageAssert.replyTo()
- An assertion for a message's “Reply-To” headerMessageAssert.to()
- An assertion for a message's “To” headerMessageAssert.cc()
- An assertion for a message's “Cc” headerMessageAssert.bcc()
- An assertion for a message's “Bcc” headerMessageAssert.subject()
- An assertion for a message's “Subject” headerPartAssert.dkimSignature(Map<String, String> publicKeys)
- An assertion for the part's DKIM signaturePartAssert.headerValue(String name)
- An assertion for a part's header (String value)PartAssert.headerValues(String name)
- An assertion for a part's header (multiple Strings values)PartAssert.dateHeaderValue(String name)
- An assertion a part's header (date value)PartAssert.dateHeaderValues(String name)
- An assertion for a part's header (multiple date values)PartAssert.textContent()
- An assertion for a part's text contentPartAssert.binaryContent()
- An assertion for a part's binary contentPartAssert.isMultipart()
- Asserts that a part has multipart contentPartAssert.multipartContent()
- An assertion for a part's multipart contentPartAssert.multipartContents()
- An assertion for a part's multipart contents (recursive)DkimSignatureAssert.isValid()
- Asserts that a DKIM signature is validDkimSignatureAssert.records()
- An assertion for the signature records of a DKIM signatureMultipartAssert.contentType()
- An assertion for a multipart's content typeMultipartAssert.parts()
- An assertion for a multipart's actual partsInternetAddressAssert.address()
- An assertion for an address' address partInternetAddressAssert.personal()
- An assertion for an address' name part