Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EasyMock to Mockito #454

Open
jpraet opened this issue Jan 7, 2024 · 1 comment
Open

EasyMock to Mockito #454

jpraet opened this issue Jan 7, 2024 · 1 comment
Labels
recipe Recipe request

Comments

@jpraet
Copy link

jpraet commented Jan 7, 2024

What problem are you trying to solve?

Migrate from EasyMock to Mockito.

Resources:

@timtebeek timtebeek added the recipe Recipe request label Jan 8, 2024
@timtebeek
Copy link
Contributor

Hi @jpraet ! Thanks for the suggestion; looking at the gist link this appears relatively straightforward:

  sed -i 's/org.easymock.EasyMock.createNiceMock/org.mockito.Mockito.mock/g' $item
  sed -i 's/org.easymock.EasyMock.createMock/org.mockito.Mockito.mock/g' $item
  sed -i 's/org.easymock.EasyMock.expect/org.mockito.Mockito.when/g' $item
  sed -i 's/org.easymock.EasyMock/org.mockito.Mockito/g' $item
  sed -i 's/EasyMock/Mockito/g' $item
  sed -i 's/createNiceMock/mock/g' $item
  sed -i 's/createMock/mock/g' $item
  sed -i 's/expect(/when(/g' $item
  sed -i 's/andReturn/thenReturn/g' $item
  sed -i 's/\.anyTimes()//g' $item
  sed -i '/replay[^A-Za-z0-9]/d' $item

At first glance most, if not all of these can be converted to use recipes we already have which you can compose in our recipe builder at https://app.moderne.io/recipes/builder
For instance the first conversion could be replaced by

type: specs.openrewrite.org/v1beta/recipe
name: java.testing.easymock.EasyMockToMockito
displayName: Migrate from EasyMock to Mockito
description: This recipe will apply changes commonly needed when migrating from EasyMock to Mockito.
recipeList:
  - org.openrewrite.java.ChangeMethodTargetToStatic:
      methodPattern: org.easymock.EasyMock createNiceMock(..)
      fullyQualifiedTargetTypeName: org.mockito.Mockito
  - org.openrewrite.java.ChangeMethodName:
      methodPattern: org.mockito.Mockito createNiceMock(..)
      newMethodName: mock
...

We already have a very similar recipe for JMockit: https://github.com/openrewrite/rewrite-testing-frameworks/blob/main/src/main/resources/META-INF/rewrite/jmockit.yml

Would you be willing to create a first draft of these migration recipes to get this started?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Status: Recipes Wanted
Development

No branches or pull requests

2 participants