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

In Jmockit to Mockito recipe, times=0 should be replaced with never() and times(1) should not occur

Open shivanisky opened this issue 1 year ago • 1 comments

What problem are you trying to solve?

In Jmockit to Mockito recipe, when migrating JMockit Expectation, if times=0 then it is migrated to verify(obj, times(0)).method() but Mockito.never() is more appropriate ie verify (obj, never()).method()

For Expectations with times=1 this should be migrated to a basic Mockito when with no times information, as that is the default when statement. Instead it is migrated to verify(obj, times(1)).method(); but should be verify(obj).method();

This may be quite easy to implement.

shivanisky avatar Aug 07 '24 12:08 shivanisky

Good improvements, thanks! Could even be separate recipes that are run after a migration, as they are just better patterns to use with Mockito, if we can make that work despite Mockito's troublesome type attribution at times. Could fold those into a Mockito best practices recipe to then improve the quality of Mockito usage independent of a migration, and is hopefully easier to manage going forward.

timtebeek avatar Aug 07 '24 12:08 timtebeek

Thanks again for the suggestion! Added the recipe in https://github.com/openrewrite/rewrite-testing-frameworks/commit/dd2992ce6cbaf8abc6980125113fcb1ef82bb5bc, and hooked it into the JMockit migration in https://github.com/openrewrite/rewrite-testing-frameworks/commit/91bc4a09cac9d805eedc3759a96868ced6fcce8b

timtebeek avatar Dec 13 '24 23:12 timtebeek