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

Use MockitoAnnotations.openMocks() instead of MockitoAnnotations.initMocks() #360

Merged
merged 2 commits into from
Nov 1, 2021

Conversation

brfrn169
Copy link
Collaborator

@brfrn169 brfrn169 commented Oct 31, 2021

We introduced Mockito 3 in #348. And MockitoAnnotations.initMock() is deprecated and replaced with MockitoAnnotations.openMocks() in Mockito 3. This PR replaces MockitoAnnotations.initMock() with MockitoAnnotations.openMocks(). Please take a look!

@brfrn169 brfrn169 self-assigned this Oct 31, 2021
Copy link
Contributor

@feeblefakie feeblefakie left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

The doc says openMocks(this).close() is equivalent to initMocks but I wonder how they can be equivalent.

@brfrn169
Copy link
Collaborator Author

brfrn169 commented Nov 1, 2021

@feeblefakie Thank you for taking look at this!

The doc says openMocks(this).close() is equivalent to initMocks but I wonder how they can be equivalent.

It looks like unless we use static-mocks or custom MockMakers, we can call the close method immediately.

The close method should however only be called after completed usage of testClass. If using static-mocks or custom org.mockito.plugins.MockMakers, using this method might cause misbehavior of mocks injected into the test class.

Copy link
Contributor

@thongdk8 thongdk8 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@brfrn169 brfrn169 merged commit e432f58 into master Nov 1, 2021
@brfrn169 brfrn169 deleted the use-openMocks branch November 1, 2021 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants