rewrite-testing-frameworks icon indicating copy to clipboard operation
rewrite-testing-frameworks copied to clipboard

PowerMockito `doThrow(Throwable).when(Class, String, any())` not converted to Mockito single argument `when`

Open anand188 opened this issue 1 year ago • 5 comments
trafficstars

I am using

org.openrewrite.maven rewrite-maven-plugin 5.39.2 true org.openrewrite.java.testing.mockito.ReplacePowerMockito org.openrewrite.recipe rewrite-testing-frameworks 2.17.0

Is your project a single module or a multi-module project? Yes

Can you share your configuration so that we can rule out any configuration issues?

Is your project public? If so, can you share a link to it? no

anand188 avatar Sep 10 '24 10:09 anand188

Hi @anand188 ; There's been a recent fix to the Powermock migration recipe in:

  • https://github.com/openrewrite/rewrite-testing-frameworks/pull/588

Would you mind trying again with the latest version? https://github.com/openrewrite/rewrite-testing-frameworks/releases/tag/v2.17.1

Beyond that your question lacks the details we need to replicate the issue; if the problems persist with the latest version I suggest you create a minimal reproducer.

timtebeek avatar Sep 10 '24 11:09 timtebeek

@timtebeek tried 2.17.1 also doesn't seem to address the issue same not completing migrating.

anand188 avatar Sep 10 '24 11:09 anand188

PowerMockito.doThrow(new IllegalArgumentException()).when( xx.class,"abc",any()) these are still not migrated because when in Mockito only takes single argument unlike PowerMockito

anand188 avatar Sep 10 '24 11:09 anand188

Ah yes that form is not yet support; that makes this sounds more like a feature request to expand coverage of our Powermock migration recipe. Would you be willing to help out with it's implementation?

The first step would be a draft pull request that adds your case to this unit test; we can collaborate from there: https://github.com/openrewrite/rewrite-testing-frameworks/blob/e9497f1a56e075d5359a10b6356d580dc0ac5874/src/test/java/org/openrewrite/java/testing/mockito/ReplacePowerMockitoIntegrationTest.java#L620-L661

timtebeek avatar Sep 10 '24 12:09 timtebeek

@timtebeek thanks let me see if its possible for me to learn and update this

anand188 avatar Sep 13 '24 06:09 anand188

Is this issue still being followed up? Similar issues. PowerMockito.when(mockResource, "activelicense", any(), any()).thenCallRealMethod(); The actual situation is Mockito.when(mockResource, "activelicense", any(), any()).thenCallRealMethod(); The expectation isMockito.when(mockResource.activelicense(any(), any()).thenCallRealMethod();

https://docs.openrewrite.org/recipes/java/testing/mockito/replacepowermockito

Rewrite Testing Frameworks 3.14.1 rewrite-maven-plugin 6.15.0

ChenyuWang98 avatar Aug 06 '25 03:08 ChenyuWang98

hi @ChenyuWang98 ; while we'd love to support it I don't have time to fit this in myself; welcome to take a stab at it if you're looking to help out! 🙏🏻

timtebeek avatar Aug 13 '25 15:08 timtebeek