Skip to content

Migrate EasyMock expectLastCall() - #1271

Open
krlittle wants to merge 1 commit into
mainfrom
ken/easymock-expect-last-call
Open

krlittle wants to merge 1 commit into
mainfrom
ken/easymock-expect-last-call

Conversation

@krlittle

@krlittle krlittle commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What's changed?

New EasyMockExpectLastCallToMockito for the recorded call + expectLastCall() pair:

dependency.action("a", 1);
expectLastCall().andThrow(new IllegalStateException());

becomes

doThrow(new IllegalStateException()).when(dependency).action("a", 1);

Same for andReturn, andAnswer and andDelegateTo (and the andStub* variants). If expectLastCall() only sets a count (times, once, anyTimes, ...) both statements are removed, since a Mockito mock accepts the call anyway. An expectLastCall() right after an expect(..) gets folded into that expectation.

What's your motivation?

Fixes #738. expectLastCall() ended up as Mockito.expectLastCall(), which doesn't exist. It was the most common thing the recipe was missing, roughly half of the EasyMock repos I ran it on use it.

Anything in particular you'd like reviewers to focus on?

doAnswer(answer) only gets proper types once IAnswer is migrated as well, which is #1270.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Nov 2, 2026
@krlittle krlittle changed the title Migrate EasyMock expectLastCall() to Mockito do*().when(mock) stubbing Migrate EasyMock expectLastCall() Nov 2, 2026
@timtebeek
timtebeek force-pushed the ken/easymock-expect-last-call branch from 1eda2e8 to 67ed61c Compare November 18, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

EasyMock to Mockito missing expectLastCall conversion

1 participant