Skip to content

Commit 99acb8f

Browse files
authored
Clarify usage for tests with JVM system properties (#53)
1 parent 68d7902 commit 99acb8f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.adoc

+38
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,44 @@ Message[] msgs = folder.getMessages();
4545
This allows you to test both the sending side and receiving side.
4646
All you need to do is to drop the JAR in the classpath during the test.
4747

48+
== Enforcing usage in tests
49+
50+
This library works thanks to the https://jakarta.ee/specifications/mail/2.1/apidocs/jakarta.mail/jakarta/mail/session#getProvider(java.lang.String)[JavaMail API] which allows to use different providers implementation to handle actual email sending.
51+
52+
To ensure it's used in your tests, you need to define the following Java system properties:
53+
54+
`mail.smtp.class`:: set to `org.jvnet.mock_javamail.MockTransport`
55+
`mail.pop3.class`:: set to `org.jvnet.mock_javamail.MockStore`
56+
`mail.imap.class`:: set to `org.jvnet.mock_javamail.MockStore`
57+
58+
This can be done either manually or via a configuration in your test runner.
59+
60+
=== Maven
61+
62+
For example, with Maven this can be done with the following configuration:
63+
64+
[source,xml]
65+
----
66+
<project>
67+
[…]
68+
<build>
69+
<plugins>
70+
<plugin>
71+
<groupId>org.apache.maven.plugins</groupId>
72+
<artifactId>maven-surefire-plugin</artifactId>
73+
<configuration>
74+
<systemPropertyVariables>
75+
<mail.smtp.class>org.jvnet.mock_javamail.MockTransport</mail.smtp.class>
76+
<mail.pop3.class>org.jvnet.mock_javamail.MockStore</mail.pop3.class>
77+
<mail.imap.class>org.jvnet.mock_javamail.MockStore</mail.imap.class>
78+
</systemPropertyVariables>
79+
</configuration>
80+
</plugin>
81+
</plugins>
82+
</build>
83+
</project>
84+
----
85+
4886
== Testing error handling behaviors
4987

5088
`Mailbox` can be marked as 'error' programatically, which causes all sending/receiving operations to fail.

0 commit comments

Comments
 (0)