View on GitHub

examples

Email testing and SMS verification examples using MailSlurp and a wide range of frameworks.

Java Maven JUnit Email OTP Match Test

This project is a Java + Maven + JUnit test that validates an email OTP signup flow end to end using MailSlurp (MailSoup).

It demonstrates a common system-test pattern:

  1. Create an isolated inbox.
  2. Trigger signup in the system under test.
  3. Wait for a matching email by subject.
  4. Extract the OTP code from email content.
  5. Submit the code to confirm signup.
  6. Login and verify success.

The implementation is designed for broad runtime compatibility:

Canonical Test

Primary test file:

The test uses:

The README flow is intentionally kept in sync with this canonical test implementation.

Endpoints Used

MailSlurp API endpoints:

Sample application endpoints under test:

Method References

MailSlurp API docs:

Sample endpoint behavior and expected responses:

Environment Variables

Makefile includes ../.env and supports these variables:

Run

make test

Using Maven directly

MAILSLURP_API_KEY=your_api_key_here mvn -q -Dtest=EmailOtpMatchFlowTest test

How Waiting and Matching Works

The test uses POST /waitForMatchingEmails with:

This pattern avoids arbitrary sleep/retry loops and waits for the specific expected message.

How Code Extraction Works

The test calls POST /emails/{emailId}/contentMatch with regex:

Then it reads capture group 1 from matches[1], and posts that value to:

After confirmation it validates login via: