openrewrite / openrewrite/rewrite-testing-frameworks

JMock to Mockito Migration

Open
#529 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

mockito recipe
Dominant language
Java
Stars
100
Forks
105
Avg merge
2h 25m
Merged PRs (30d)
9

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the issue's Java before-and-after examples and the stated Mockito v5.x precondition, then inspect existing recipe conventions in the repository. Done means a recipe and tests cover the shown JMock expectations-to-Mockito transformation and preserve the intended property values.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.