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
Fixes #2281: Make MockedConstruction stubs close on demand #2442
Conversation
MockedConstruction should behave like MockedStatic when we use @mock on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the regression test that you mentioned in your PR description to our test suite in https://github.com/mockito/mockito/tree/main/subprojects/junit-jupiter/src/test/java/org/mockitousage
MockedConstruction should behave like MockedStatic when we use @mock on it.
Hi @TimvdLippe , tests have been added. Feel free to mention if something needs to be changed! Sorry if I messed up with the merge (not sure why it was needed), I hope we can squash everything before merging to hide it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obvious oversight. Good to merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks good to me. We can clean up the commit message when we squash-merge, so don't worry about that 😄
Only a small nit with regard to the missing license. Other than that this is ready to go.
subprojects/junit-jupiter/src/test/java/org/mockitousage/CloseOnDemandTest.java
Outdated
Show resolved
Hide resolved
* Tests to assert that ScopedMock mocks are properly closed on scope exit. | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
class CloseOnDemandTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh, my apologies. Since this only works for the inline mockmaker, the test file needs to be in https://github.com/mockito/mockito/tree/main/subprojects/junitJupiterInlineMockMakerExtensionTest/src/test/java/org/mockitousage
Please run ./gradlew build
locally to ensure that the tests pass before you update the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, and thank you for pointing that out, I was getting confused by the error message.
Also the project was building fine locally, which I find suspicious based on the error message I receive on Github.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
MockedConstruction should behave like MockedStatic when we use @mock on it.
Checklist
including project members to get a better picture of the change
commit is meaningful and help the people that will explore a change in 2 years
Fixes #<issue number>
in the description if relevantFixes #<issue number>
if relevantAllows this kind of test to work in multiple test files:
Otherwise the
mockConstruction
object won't be closed and generate error described in #2281.