-
Notifications
You must be signed in to change notification settings - Fork 75
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
@ExtendWith and @ContextConfguration can be simplified to @SpringJUnitConfig #296
Comments
Nice suggestion for another cleanup indeed! |
* Add recipe to replace @ExtendWith and @ContextConfiguration with @SpringJUnitConfig (#296) * Override getSingleSourceApplicableTest for UsesType checks Also apply default formatter for consistency * Adopt String.formatted instead of String concatenation * Consistently use replace with instead of into * Adopt Applicability.and(..) to require both annotations * Move and temporarily disable inclusion in update chain --------- Co-authored-by: Tim te Beek <tim@moderne.io>
Reopened as per the final comment on #297 (comment). We want to try this out on a number of Spring projects through public.moderne.io, so ensure there are no edge cases left uncovered before we hook this into the chain of upgrade recipes by default. |
@nbruno I've just updated the platform to include your recipe: https://public.moderne.io/recipes/org.openrewrite.java.spring.boot2.ReplaceExtendWithAndContextConfiguration When I run that recipe in isolation against 49 Spring projects, you get the following results: https://public.moderne.io/results/kfx9I For the top one you can then create a fork, as I've done, to check that out and confirm it's working locally. Once confirmed you can then create a pull request to contribute back to Spring if you'd like. Also let me know if you'd like me to include any of your own (public) projects in the platform to verify the recipe! Once we have a decent sampling covered we can hook the recipe up for inclusion in the default migration chain, as discussed. |
Confirmed to work locally for spring-data-jpa already: promising! |
Awesome! Opened the draft PR to enable this in the default migration chain. Feel free to submit PR's to the Spring repositories if it'd be beneficial for them. |
Spring introduced the
@SpringJUnitConfig
annotation as a composed annotation for@ExtendWith(SpringExtension.class)
and@ContextConfiguration
. A recipe should be created to perform this migration.The recipe should transform the following code:
Into:
Note that
@SpringJUnitConfig
contains aliases for the following@ContextConfiguration
attributes which should be maintained from the original@ContextConfiguration
annotation when creating the@SpringJUnitConfig
annotation:It would be beneficial to also include this in the migration from JUnit4 to JUnit5 recipe, possibly as another step of the recipe that removes unnecessary
@RunWith
annotations or as a top-level recipe addition to the migration recipe.The text was updated successfully, but these errors were encountered: