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

JMock to Mockito Migration #529

Open
alfarhanzahedi opened this issue Jun 17, 2024 · 4 comments
Open

JMock to Mockito Migration #529

alfarhanzahedi opened this issue Jun 17, 2024 · 4 comments
Labels
mockito recipe Recipe request

Comments

@alfarhanzahedi
Copy link

What problem are you trying to solve?

I am trying to migrate from JMock to Mockito. Multiple of my projects use a combination of JMock and Mockito for unit testing. I am trying to consolidate the tests to just use Mockito.

What precondition(s) should be checked before applying this recipe?

Mockito v5.x should be preferable.

Describe the situation before applying the recipe

    @Test
    public void sampleTest() {
        ...
        mockery.checking(new Expectations() {

            {
                allowing(objectOne).getPropertyOne();
                will(returnValue(propertyOneValue));
                allowing(objectTwo).getPropertyTwo();
                will(returnValue(propertyTwoValue));
            }
        });
        ...
    }

Describe the situation after applying the recipe

    @Test
    public void sampleTest() {
        when(objectOne.getPropertyOne()).thenReturn(propertyOneValue);
        when(objectTwo.getPropertyTwo()).thenReturn(propertyTwoValue);
    }

Have you considered any alternatives or workarounds?

Apart from doing a manual migration, no.

Are you interested in contributing this recipe to OpenRewrite?

Yes. I am interested :D

@alfarhanzahedi
Copy link
Author

If there's already a recipe that solves this, do share. I could not find one.

@timtebeek timtebeek transferred this issue from openrewrite/rewrite Jun 17, 2024
@timtebeek timtebeek added the recipe Recipe request label Jun 17, 2024
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Jun 17, 2024
@timtebeek
Copy link
Contributor

hi @alfarhanzahedi ! There certainly is no shortage of mocking libraries with Java is there? 😅

We already have recipes to go from JMockit to Mockito, as well as from PowerMock and older versions of Mockito to v5. We also have requests to cover additional libraries & cases such as

Thanks for the offer to help cover JMock as well! From the recipes we have already I think there should be some decent examples in there on how to achieve such a migration. Feel free to start a draft PR with just some tests early to get feedback on where to go next. Typically we find that some initial steps are easy to add, and then from there look at what's needed to get decent coverage for a mostly automated migration.

@dionmeijer
Copy link

I would be interested in using this recipe too. 👍

@timtebeek
Copy link
Contributor

Glad to hear! Feel free to kick this off with a draft pull request containing just the tests, and then I'll try to guide you from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mockito recipe Recipe request
Projects
Status: Recipes Wanted
Development

No branches or pull requests

3 participants