MockitoWhenOnStaticToMockStatic: name unnamed _ variable when reusing MockedStatic#1060
Merged
Conversation
…ng MockedStatic When a `MockedStatic` was held in an unnamed variable (`try (var _ = Mockito.mockStatic(A.class))`), the recipe emitted `_.when(...)`, which does not compile. Rename the resource to a generated name and use that when reusing the existing `MockedStatic`. Build tests on Java 25 with `rewrite-java-25` so unnamed `_` variables parse.
timtebeek
marked this pull request as draft
July 23, 2026 17:02
Member
Author
|
Needs a bump to Java 25 first, which we'll explore separately given that there's failures on main on Java 25. |
timtebeek
marked this pull request as ready for review
July 25, 2026 07:07
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
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.
Fixes #1051. When a
MockedStaticis held in an unnamed variable (try (var _ = Mockito.mockStatic(A.class))), the recipe emitted_.when(...), which does not compile; it now renames the resource to a generated name (e.g.mockA1) and uses that when reusing the existingMockedStatic, and renames multiple_resources individually.Blocked / draft: the added tests use unnamed
_variables, a Java 22+ feature that only parses withrewrite-java-25. This repo currently builds/tests on Java 21, so CI is red until the separate "migrate to build on Java 25" change lands onmain; this PR should then be rebased (it carries no build changes of its own).