openrewrite / openrewrite/rewrite-testing-frameworks
EasyMock to Mockito missing `expectLastCall` conversion
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 100
- Forks
- 105
- Avg merge
- 2h 25m
- Merged PRs (30d)
- 9
Description
What version of OpenRewrite are you using?
I guess that RELEASE version right now are
- org.openrewrite:rewrite-bom 8.53.0
- org.openrewrite:rewrite-maven-plugin 6.9.0
- org.openrewrite.recipe:rewrite-testing-frameworks 3.8.0
How are you running OpenRewrite?
I am using this maven cli
MAVEN_OPTS="-Xmx16g -XX:-MaxFDLimit" mvn --debug -Denforcer.skip org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-testing-frameworks:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.testing.easymock.EasyMockToMockito -Drewrite.exportDatatables=true
What is the smallest, simplest way to reproduce the problem?
I have a test case using expectLastCall()
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expectLastCall;
class ATest {
@Test
public void test0SimpleRequest() {
TicketPassenger ticket = /* --- */;
TicketingService ticketingService = createMock(TicketingService.class);
ticketingService.findCouponByNumber(eq(ticketNumber), eq(1));
expectLastCall().andReturn(ticket.getAllCoupons().get(0));
//...
}
}
What did you expect to see?
I expected the expectLastCall().andReturn call chain, to be refactored to a when().thenReturn chain, similar to how expect chains are refactored
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class A {
@Test
public void test0SimpleRequest() {
TicketPassenger ticket = /* --- */;
TicketingService ticketingService = mock(TicketingService.class);
when(ticketingService.findCouponByNumber(ticketNumber, 1).thenReturn(ticket.getAllCoupons().get(0));
//...
}
}
What did you see instead?
The EasyMock expectLastCall() is refactored to an non-existing org.mockito.Mockito.expectLastCall method
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.expectLastCall;
class ATest {
@Test
public void test0SimpleRequest() {
TicketPassenger ticket = /* --- */;
TicketingService ticketingService = mock(TicketingService.class);
ticketingService.findCouponByNumber(eq(ticketNumber), eq(1));
expectLastCall().thenReturn(ticket.getAllCoupons().get(0));
//...
}
}
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 by running the org.openrewrite.java.testing.easymock.EasyMockToMockito recipe from the Maven command against the expectLastCall() reproducer. Trace how expectLastCall().andReturn is converted, then verify the finished migration produces a valid Mockito when().thenReturn chain without an expectLastCall import or call.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100