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

Replace Deprecated MockitoAnnotations.initMocks #542

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

zjdaniels1985
Copy link

Replace the deprecated MockitoAnnotations.initMocks() method with the recommended Mockito.Annotations.openMocks() method

Motivation

  • initMocks was used to initialize mocks annotated with @mock, @SPY, etc., in your test class
  • openMocks is the recommended replacement since Mockito 3. It provides the same functionality but with better resource management
  • openMocks returns an AutoCloseable object, which ensures that resources are properly closed after the test execution

Changes

Old:

import org.mockito.MockitoAnnotations;

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
}

New:

import org.mockito.MockitoAnnotations;

public class <TEST-CLASS-NAME> {

private AutoCloseable closeable;

@Before
public void setUp() {
    closeable = MockitoAnnotations.openMocks(this)) {
        ...
    }
}

@After
public void releaseMocks() throws Exception {
        closeable. close();
    }
...

Copy link

cla-bot bot commented Oct 25, 2024

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @zjdaniels1985 on file. In order for us to review and merge your code, please sign our Contributor License Agreement to get yourself added. You'll find the CLA and more information here: https://github.com/hivemq/hivemq-community/blob/master/CONTRIBUTING.adoc#contributor-license-agreement

Copy link

cla-bot bot commented Oct 28, 2024

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @zjdaniels1985 on file. In order for us to review and merge your code, please sign our Contributor License Agreement to get yourself added. You'll find the CLA and more information here: https://github.com/hivemq/hivemq-community/blob/master/CONTRIBUTING.adoc#contributor-license-agreement

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

Successfully merging this pull request may close these issues.

1 participant