Skip to content

JMock to Mockito Migration #529

Description

@alfarhanzahedi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Recipes Wanted

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions