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

Keep mockStatic import in CleanupMockitoImports when type info is incomplete#1047
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant