Skip to content
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

Make MockitoExtension constructor public #1391

Merged
merged 2 commits into from May 17, 2018

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented May 17, 2018

It is possible to register an extension for automatic use using Java's ServiceLoader mechanism.

https://junit.org/junit5/docs/current/user-guide/#extensions-registration-automatic

Some projects may want to provide their own META-INF file to avoid tediously adding MockitoExtension to tests since it is very common. However, ServiceLoader requires the class to have a no-args public constructor, so the current extension cannot be used with the ServiceLoader mechanism.

Fixes #1390

check list

  • Read the contributing guide
  • PR should be motivated, i.e. what does it fix, why, and if relevant how
  • If possible / relevant include an example in the description, that could help all readers
    including project members to get a better picture of the change
  • Avoid other runtime dependencies
  • Meaningful commit history ; intention is important please rebase your commit history so that each
    commit is meaningful and help the people that will explore a change in 2 years
  • The pull request follows coding style
  • Mention Fixes #<issue number> in the description if relevant
  • At least one commit should mention Fixes #<issue number> if relevant

It is possible to register an extension for automatic use using Java's `ServiceLoader` mechanism.

https://junit.org/junit5/docs/current/user-guide/#extensions-registration-automatic

Some projects may want to provide their own `META-INF` file to avoid tediously adding `MockitoExtension` to tests since it is very common. However, `ServiceLoader` requires the class to have a no-args *public* constructor, so the current extension cannot be used with the `ServiceLoader` mechanism.
@TimvdLippe
Copy link
Contributor

Would be great if you could add a test for this. Not sure if that is possible? It is not a blocking issue for me though.

@codecov-io
Copy link

codecov-io commented May 17, 2018

Codecov Report

Merging #1391 into release/2.x will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff               @@
##             release/2.x    #1391   +/-   ##
==============================================
  Coverage          88.61%   88.61%           
  Complexity          2355     2355           
==============================================
  Files                292      292           
  Lines               5945     5945           
  Branches             718      718           
==============================================
  Hits                5268     5268           
  Misses               497      497           
  Partials             180      180

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 758ca37...7e971fd. Read the comment docs.

@anuraaga
Copy link
Contributor Author

Added a test (a bit heavyweight since it needs to be a separate project to avoid influencing others)

Copy link
Contributor

@TimvdLippe TimvdLippe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks!

@TimvdLippe TimvdLippe merged commit 3f96f3b into mockito:release/2.x May 17, 2018
@bric3 bric3 added the junit5 label Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MockitoExtension cannot be registered as a global junit5 extension.
4 participants