openrewrite / openrewrite/rewrite-testing-frameworks
JMock to Mockito Migration
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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