You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added a new recipe ExpectationsToMockito to handle converting a JMockit Expectations block to a Mockito when statement. (WIP)
Added declarative recipe org.openrewrite.java.testing.jmockit.JMockitToMockito, to eventually list all the recipes necessary for the migration.
Added a unit test JMockitToMockitoTest for testing the declarative recipe.
What's your motivation?
Work towards a full JMockit to Mockito migration recipe. This migration is quite involved for large codebases, and JMockit presents challenges for migrating to Java 17.
Checklist
I've added unit tests to cover both positive and negative cases
I've added the license header to any new files through ./gradlew licenseFormat
I've used the IntelliJ IDEA auto-formatter on affected files
tinder-dthomson
changed the title
Recipe to convert JMockit Expectations block to Mockito.when statement
JMockit to Mockito Migration - Rewrite Expectations Block
Oct 18, 2023
tinder-dthomson
changed the title
JMockit to Mockito Migration - Rewrite Expectations Block
JMockit to Mockito Migration Recipe - Rewrite Expectations Block
Oct 18, 2023
I noticed the recipes were located in the Mockito package, maybe it would be better to create a JMockit one since it's migration related to be in line with https://github.com/openrewrite/rewrite-testing-frameworks/tree/main/src/main/java/org/openrewrite/java/testing/hamcrest?
Hi Devin, Thanks for your contribution!
I updated the code and it can pass the test now, the only thing I am not quite sure about is why the when() from the template does not have a method type.
Hi Devin, Thanks for your contribution! I updated the code and it can pass the test now, the only thing I am not quite sure about is why the when() from the template does not have a method type.
Thank you so much! Do you mind explaining your changes a bit?
From what I saw, your changes can be broken into three categories:
Classpath Updates
Setting typeValidationOptions to TypeValidation.none() on the test spec parser
Using newMethod.withPrefix(newClass.getPrefix()) (curious if nc.getPrefix() would have been okay too?)
I have the following specific questions:
Were classpath updates you made were functionally necessary or simply a best practice? I couldn't tell why you added mockito-junit-jupiter-3.12 to the test parser classpath, for example.
Would using nc.getPrefix() as the param to newMethod.withPrefix() be problematic? I would guess newClass and nc are the same pointer, unless calling super.visitNewClass clones it.
Hi Devin, Thanks for your contribution! I updated the code and it can pass the test now, the only thing I am not quite sure about is why the when() from the template does not have a method type.
Thank you so much! Do you mind explaining your changes a bit?
From what I saw, your changes can be broken into three categories:
Classpath Updates
Setting typeValidationOptions to TypeValidation.none() on the test spec parser
Using newMethod.withPrefix(newClass.getPrefix()) (curious if nc.getPrefix() would have been okay too?)
I have the following specific questions:
Were classpath updates you made were functionally necessary or simply a best practice? I couldn't tell why you added mockito-junit-jupiter-3.12 to the test parser classpath, for example.
Would using nc.getPrefix() as the param to newMethod.withPrefix() be problematic? I would guess newClass and nc are the same pointer, unless calling super.visitNewClass clones it.
Adding those classpaths is to get type attributions, and we just need to add necessary minimum set of classpaths. import org.mockito.junit.jupiter.MockitoExtension I think this import requires mockito-junit-jupiter-3.12.
Yeah, using nc.getPrefix() is better here, it's supposed to be supposed to be supported by autoFormat here, but replacing the prefix also works here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's changed?
ExpectationsToMockitoto handle converting a JMockitExpectationsblock to a Mockitowhenstatement. (WIP)org.openrewrite.java.testing.jmockit.JMockitToMockito, to eventually list all the recipes necessary for the migration.JMockitToMockitoTestfor testing the declarative recipe.What's your motivation?
Work towards a full JMockit to Mockito migration recipe. This migration is quite involved for large codebases, and JMockit presents challenges for migrating to Java 17.
Checklist
./gradlew licenseFormat