Skip to content

Keep mockStatic import in CleanupMockitoImports when type info is incomplete - #1047

Merged
timtebeek merged 1 commit into
mainfrom
fix/cleanup-mockito-imports-mockstatic
Jun 23, 2026
Merged

timtebeek merged 1 commit into
mainfrom
fix/cleanup-mockito-imports-mockstatic

Conversation

@timtebeek

Copy link
Copy Markdown
Member

What's changed

CleanupMockitoImports keeps a curated list of Mockito method names (MOCKITO_METHOD_NAMES). When a call's type information isn't well-formed (e.g. an older Mockito on the classpath, or surrounding types that don't fully resolve), the recipe relies on this list to recognize the call and avoid removing the still-needed static import.

mockStatic (and its sibling mockConstruction) were missing from that list — only mock was present. As a result, import static org.mockito.Mockito.mockStatic; was wrongly removed whenever the mockStatic(...) call's type couldn't be resolved, even though it was still in use.

This PR adds mockStatic and mockConstruction to the list, and adds a reproducing test.

Context

Reported via a Moderne result on moderneinc/rewrite-ai-search where mockStatic was being stripped from SpellCheckCommentsInFrenchTest.java despite being used.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 23, 2026
@timtebeek
timtebeek merged commit 95ff73a into main Jun 23, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 23, 2026
@timtebeek
timtebeek deleted the fix/cleanup-mockito-imports-mockstatic branch June 23, 2026 07:48
mergify Bot added a commit to robfrank/linklift that referenced this pull request Jul 17, 2026
…rom 3.38.0 to 3.42.0 [skip ci]

Bumps [org.openrewrite.recipe:rewrite-testing-frameworks](https://github.com/openrewrite/rewrite-testing-frameworks) from 3.38.0 to 3.42.0.
Release notes

*Sourced from [org.openrewrite.recipe:rewrite-testing-frameworks's releases](https://github.com/openrewrite/rewrite-testing-frameworks/releases).*

> 3.42.0
> ------
>
> What's Changed
> --------------
>
> * Support Kotlin sources in `AssertThrowsOnLastStatement` by [`@​vlsi`](https://github.com/vlsi) in [openrewrite/rewrite-testing-frameworks#1048](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1048)
> * Use range selector so JUnit5to6Migration gates on Java 17 or higher by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1049](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1049)
> * Simplify JUnit5to6Migration minimum Java version to '17' by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1050](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1050)
>
> New Contributors
> ----------------
>
> * [`@​vlsi`](https://github.com/vlsi) made their first contribution in [openrewrite/rewrite-testing-frameworks#1048](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1048)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.41.0...v3.42.0>
>
> 3.41.0
> ------
>
> What's Changed
> --------------
>
> * Keep `mockStatic` import in `CleanupMockitoImports` when type info is incomplete by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1047](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1047)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.40.0...v3.41.0>
>
> v3.39.0
> -------
>
> What's Changed
> --------------
>
> * Add `PowerMockWhiteboxGetFieldToJavaReflection` recipe by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1025](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1025)
> * Add `PowerMockWhiteboxGetMethodToJavaReflection` recipe by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1026](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1026)
> * Add `PowerMockWhiteboxInvokeConstructorToJavaReflection` recipe by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1027](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1027)
> * Expand TestNG to AssertJ assertion coverage by [`@​juherr`](https://github.com/juherr) in [openrewrite/rewrite-testing-frameworks#1028](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1028)
> * Flag un-migratable PowerMock powermock-reflect usage with a comment by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1016](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1016)
>
> New Contributors
> ----------------
>
> * [`@​juherr`](https://github.com/juherr) made their first contribution in [openrewrite/rewrite-testing-frameworks#1028](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1028)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.38.0...v3.39.0>


Commits

* [`2b5d852`](openrewrite/rewrite-testing-frameworks@2b5d852) Keep Mockito dependency managed in Mockito1to3Migration multi-module builds
* [`e2dffca`](openrewrite/rewrite-testing-frameworks@e2dffca) OpenRewrite recipe best practices
* [`c709cec`](openrewrite/rewrite-testing-frameworks@c709cec) Simplify JUnit5to6Migration minimum Java version to '17' ([#1050](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1050))
* [`d3830c0`](openrewrite/rewrite-testing-frameworks@d3830c0) Use range selector so JUnit5to6Migration gates on Java 17 or higher ([#1049](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1049))
* [`b0b1f19`](openrewrite/rewrite-testing-frameworks@b0b1f19) Support Kotlin sources in `AssertThrowsOnLastStatement` ([#1048](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1048))
* [`2e6d485`](openrewrite/rewrite-testing-frameworks@2e6d485) OpenRewrite recipe best practices
* [`95ff73a`](openrewrite/rewrite-testing-frameworks@95ff73a) Keep `mockStatic` import in `CleanupMockitoImports` when type info is incompl...
* [`cba9383`](openrewrite/rewrite-testing-frameworks@cba9383) Recipe best practices
* [`9321cbc`](openrewrite/rewrite-testing-frameworks@9321cbc) Convert `assertThrows` with an `Executable` variable ([#1046](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1046))
* [`0eb4765`](openrewrite/rewrite-testing-frameworks@0eb4765) Skip JUnit 4 lifecycle annotation when Jupiter equivalent already present ([#1](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1)...
* Additional commits viewable in [compare view](openrewrite/rewrite-testing-frameworks@v3.38.0...v3.42.0)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.recipe:rewrite-testing-frameworks&package-manager=maven&previous-version=3.38.0&new-version=3.42.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 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

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant