-
Notifications
You must be signed in to change notification settings - Fork 73
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
Mockito: Recipe to replace initMocks with openMocks #512
Comments
Thanks for the suggestion @lucashan ! We should be able to convert such cases as described with a new recipe. We already have a similar recipe test to bring folks from JUnit 4 and Mockito 1 to JUnit 5 and Mockito v3; seems only logical to automate the next migration test involving Ideally we start with a unit test similar to this one, describing exactly what we should aim for with this recipe. Lines 46 to 122 in fafcb85
|
What problem are you trying to solve?
When upgrading Java applications and Mockito version, there is a MockitoAnnotiations API (
initMocks
) that is deprecated (see mockito-core 3.4.0 documentation for details).What precondition(s) should be checked before applying this recipe?
The recommendation is to replace
initMocks
withopenMocks(Object)
, which is equivalent toopenMocks(testClass).close()
. The close method should however only be called after completed usage of testClass. If using static-mocks or custom MockMakers, using this method might cause misbehavior of mocks injected into the test class.Have you considered any alternatives or workarounds?
N/A
Any additional context
I'm not entirely sure if OpenRewrite has an existing utilities/mechanisms to simplify such complex refactorings, I wanted to surface this issue to check if there are any.
Are you interested in contributing this recipe to OpenRewrite?
N/A
The text was updated successfully, but these errors were encountered: