Skip to content

EasyMock to Mockito missing expectLastCall conversion #738

@hkampbjorn

Description

@hkampbjorn

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));
//...
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingrecipeRecipe request

    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