Update MockWebServer MockResponse test for nested-type render change#1020
Merged
steve-aom-elliott merged 1 commit intoJun 15, 2026
Merged
Conversation
…ange rewrite-core no longer rewrites a variable's declared type via ChangeMethodInvocationReturnType when the matched invocation is nested in the initializer rather than the initializer itself (openrewrite/rewrite#7993). The declared type is now changed by ChangeType, which renders the nested Builder as the qualified `MockResponse.Builder` (reusing the outer import) instead of importing `MockResponse.Builder` and using the simple name. Update the expected output of shouldMigrateMockResponseToBuilder to match, consistent with how mockResponse2 already renders in the same test.
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.
The
UpdateMockWebServerMockResponseTest.shouldMigrateMockResponseToBuilder()test started failing against the latestrewritesnapshot (8.85.0-SNAPSHOT).Root cause
ChangeMethodInvocationReturnTypeto rewrite a variable’s declared type only when the variable’s initializer is the matched invocation, not when the match is merely nested inside the initializer.In this test,
mockResponse’s initializer is a chain whose outermost call issetHeader(...), which is not in the recipe’s replacement map — so the matchedsetStatus(...)is nested, not the initializer. The declared-type change is therefore now performed by the laterChangeTypestep (rather thanChangeMethodInvocationReturnType), andChangeTyperenders the nested type in qualifiedMockResponse.Builderform (reusing the existingmockwebserver3.MockResponseimport) instead of importingmockwebserver3.MockResponse.Builderand using the simple nameBuilder.Change
Update the expected output of
shouldMigrateMockResponseToBuilder:This matches the new (more correct, consistent) output —
mockResponse2in the same test already renders asMockResponse.Builder.Verification
org.openrewritemodules to8.84.7(pre-#7993): test passes.8.85.0-SNAPSHOT(has #7993): test fails before this change, passes after.