Skip to content

Clarify the library depends on classpath ordering #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gaeljw opened this issue Mar 14, 2023 · 2 comments · Fixed by #53
Closed

Clarify the library depends on classpath ordering #49

gaeljw opened this issue Mar 14, 2023 · 2 comments · Fixed by #53

Comments

@gaeljw
Copy link
Contributor

gaeljw commented Mar 14, 2023

Describe your use-case which is not covered by existing documentation.

I started using the library for tests in some projects but I encountered an issue in IntelliJ where tests were still using the real email library (see initial bug report at IntelliJ team).

After troubleshooting by Jetbrains team, it seems that the behaviour is highly dependent on classpath ordering: depending on which order libs are loaded, you might be using the mock-javamail or the real email stack.

That sounds kinda risky and IMHO should be at least explicitly stated in the documentation (I guess the README is a good start).

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

@gaeljw gaeljw changed the title Clarify how the library works Clarify the library depends on classpath ordering Mar 14, 2023
@basil
Copy link
Member

basil commented Apr 11, 2023

Per the JavaMail API docs:

Checks mail.<protocol>.class property first and if it exists, returns the Provider associated with this implementation. If it doesn't exist, returns the Provider that appeared first in the configuration files.

So I think you should be able to define the Java system properties

  • mail.smtp.class set to org.jvnet.mock_javamail.MockTransport
  • mail.pop3.class set to org.jvnet.mock_javamail.MockStore
  • mail.imap.class set to org.jvnet.mock_javamail.MockStore

in your test runner (see this page for a Maven example) to eliminate the classpath order fragility. Play around with this in the debugger; if you get it to work, we would love a pull request updating the documentation!

@gaeljw
Copy link
Contributor Author

gaeljw commented Apr 13, 2023

Ah right, this is what I was looking for.

I'll provide a PR to make this clear in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants