-
Notifications
You must be signed in to change notification settings - Fork 88
MockitoJUnitRunnerToExtension: Handle existing MockitoExtension #788
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
Merged
Conversation
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
@timtebeek can you please review. |
Yes had it open but was our tonight I'll look to get this in before the next release, thanks! |
timtebeek
approved these changes
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes here! Wasn't expected indeed that classes would already have both, but good to handle that gracefully.
mergify bot
added a commit
to robfrank/linklift
that referenced
this pull request
Aug 15, 2025
…rom 3.11.0 to 3.15.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-testing-frameworks](https://github.com/openrewrite/rewrite-testing-frameworks) from 3.11.0 to 3.15.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-testing-frameworks's releases](https://github.com/openrewrite/rewrite-testing-frameworks/releases).* > 3.15.0 > ------ > > What's Changed > -------------- > > * Include additional AssertJ migrations by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#773](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/773) > * Include recipes in larger composites where possible by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#774](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/774) > * Retain comments when chaining assertions by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#775](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/775) > * refactor: Static imports for Collections and Collectors by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#779](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/779) > * Added implementation to extract any expression arguments from last statement in assertThrows by [`@JohannisK`](https://github.com/JohannisK) in [openrewrite/rewrite-testing-frameworks#724](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/724) > * Don't clean up mockito imports for Kotlin by [`@jevanlingen`](https://github.com/jevanlingen) in [openrewrite/rewrite-testing-frameworks#782](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/782) > * Adding dependency guards to the Junit 4 -> 5 migration for when the POM or build.gradle have a dependency on `org.testng:testng`. by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#760](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/760) > * rename settings.local.json to settings.json by [`@zieka`](https://github.com/zieka) in [openrewrite/rewrite-testing-frameworks#783](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/783) > * Fix ClassCastException in PowerMockitoWhenNewToMockito by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#786](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/786) > * MockitoJUnitRunnerToExtension: Handle existing MockitoExtension by [`@amishra-u`](https://github.com/amishra-u) in [openrewrite/rewrite-testing-frameworks#788](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/788) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.14.0...v3.15.0> > > 3.14.1 > ------ > > What's Changed > -------------- > > * OpenRewrite v8.59.1: <https://github.com/openrewrite/rewrite> > > **Full Changelog**: <https://github.com/openrewrite/rewrite-testing-frameworks> > > 3.14.0 > ------ > > What's Changed > -------------- > > * Collapse more consecutive assertions by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#769](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/769) > * refactor: Unwrap else block after return or throw statement by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#771](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/771) > * Remove all PowerMock imports after migration by [`@JohannisK`](https://github.com/JohannisK) in [openrewrite/rewrite-testing-frameworks#770](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/770) > * Remove `assertTrue(true)` and `assertFalse(false)` by [`@aet2505`](https://github.com/aet2505) in [openrewrite/rewrite-testing-frameworks#767](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/767) > > New Contributors > ---------------- > > * [`@aet2505`](https://github.com/aet2505) made their first contribution in [openrewrite/rewrite-testing-frameworks#767](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/767) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.13.0...v3.14.0> > > 3.13.0 > ------ > > What's Changed > -------------- > > * Removing `NoInitializationForInjectMock` recipe due to side effects when using recipe by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#765](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/765) > * Adding functionality to `MockitoWhenOnStaticToMockStatic` for recognizing an existing try-with-resources `MockedStatic<T>` can be reused instead of creating a new one. by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#766](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/766) > * Inconvertible Mockito `when` situation involving lambda and static method. by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#763](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/763) > * Changing order of `mockito-all` -> `mockito-core` change vs `org.mockito:*` upgrade, and made the former upgrade to `3.x` at the same time, as there aren't aligned versions between the two. by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#768](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/768) > > New Contributors > ---------------- > > * [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) made their first contribution in [openrewrite/rewrite-testing-frameworks#765](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/765) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.12.0...v3.13.0> > > 3.12.0 > ------ > > What's Changed > -------------- > > * Fix for JUnit test method throws clause preservation by [`@knutwannheden`](https://github.com/knutwannheden) in [openrewrite/rewrite-testing-frameworks#755](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/755) > * refactor: org.openrewrite.mavencentral by [`@Laurens-W`](https://github.com/Laurens-W) in [openrewrite/rewrite-testing-frameworks#756](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/756) ... (truncated) Commits * [`76c6888`](openrewrite/rewrite-testing-frameworks@76c6888) MockitoJUnitRunnerToExtension: Handle existing MockitoExtension ([#788](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/788)) * [`75d2019`](openrewrite/rewrite-testing-frameworks@75d2019) Retain `Throwable` in `SimplifyTestThrows` * [`0ea47e9`](openrewrite/rewrite-testing-frameworks@0ea47e9) Include `SimplifyTestThrows` with `JUnit5BestPractices` * [`efb0a4e`](openrewrite/rewrite-testing-frameworks@efb0a4e) Add AssertJ change type recipes for classes deprecated in v3.27.4 * [`f203a20`](openrewrite/rewrite-testing-frameworks@f203a20) Update documentation examples * [`69d7716`](openrewrite/rewrite-testing-frameworks@69d7716) Fix ClassCastException in PowerMockitoWhenNewToMockito ([#786](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/786)) * [`dc6f272`](openrewrite/rewrite-testing-frameworks@dc6f272) rename settings.local.json to settings.json ([#783](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/783)) * [`96fca52`](openrewrite/rewrite-testing-frameworks@96fca52) Documentation example for MockitoJUnitRunnerToExtensionTest * [`9a2082a`](openrewrite/rewrite-testing-frameworks@9a2082a) Adding dependency guards to the Junit 4 -> 5 migration for when the POM or bu... * [`74366cf`](openrewrite/rewrite-testing-frameworks@74366cf) OpenRewrite recipe best practices * Additional commits viewable in [compare view](openrewrite/rewrite-testing-frameworks@v3.11.0...v3.15.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?
This PR updates the MockitoJUnitRunnerToExtension recipe to better handle the migration from MockitoJUnitRunner to MockitoExtension. Specifically:
What's your motivation?
In some cases a developer may have bothe MockitoRule and MockitoJunitRunner both in same test class. In that case the MockitoJUnitToMockitoExtension and MockitoJUnitRunnerToExtension both tries to add
MockitoExtension
orMockitoSettings
which is not repeatable and test fails with compilation error. Updated MockitoJUnitRunnerToExtension to not add these extension if one already exists, Since MockitoJUnitRunnerToExtension recipes runs after MockitoJUnitToMockitoExtension Junit4toJunit5 recipe.Checklist