Skip to content

Update MockWebServer MockResponse test for nested-type render change#1020

Merged
steve-aom-elliott merged 1 commit into
mainfrom
fix/mockwebserver-builder-nested-type-render
Jun 15, 2026
Merged

Update MockWebServer MockResponse test for nested-type render change#1020
steve-aom-elliott merged 1 commit into
mainfrom
fix/mockwebserver-builder-nested-type-render

Conversation

@steve-aom-elliott

@steve-aom-elliott steve-aom-elliott commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

The UpdateMockWebServerMockResponseTest.shouldMigrateMockResponseToBuilder() test started failing against the latest rewrite snapshot (8.85.0-SNAPSHOT).

Root cause

  • openrewrite/rewrite#7993 changed ChangeMethodInvocationReturnType to 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 is setHeader(...), which is not in the recipe’s replacement map — so the matched setStatus(...) is nested, not the initializer. The declared-type change is therefore now performed by the later ChangeType step (rather than ChangeMethodInvocationReturnType), and ChangeType renders the nested type in qualified MockResponse.Builder form (reusing the existing mockwebserver3.MockResponse import) instead of importing mockwebserver3.MockResponse.Builder and using the simple name Builder.

Change

Update the expected output of shouldMigrateMockResponseToBuilder:

 import mockwebserver3.MockResponse;
-import mockwebserver3.MockResponse.Builder;
 ...
-    private Builder mockResponse = new MockResponse.Builder()
+    private MockResponse.Builder mockResponse = new MockResponse.Builder()

This matches the new (more correct, consistent) output — mockResponse2 in the same test already renders as MockResponse.Builder.

Verification

  • Pinned core org.openrewrite modules to 8.84.7 (pre-#7993): test passes.
  • Against 8.85.0-SNAPSHOT (has #7993): test fails before this change, passes after.

…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.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 15, 2026
@steve-aom-elliott steve-aom-elliott added bug Something isn't working recipe Recipe request test provided labels Jun 15, 2026
@steve-aom-elliott steve-aom-elliott moved this from In Progress to Ready to Review in OpenRewrite Jun 15, 2026
@steve-aom-elliott steve-aom-elliott merged commit ff368ff into main Jun 15, 2026
1 check passed
@steve-aom-elliott steve-aom-elliott deleted the fix/mockwebserver-builder-nested-type-render branch June 15, 2026 16:36
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Jun 15, 2026
mergify Bot added a commit to robfrank/linklift that referenced this pull request Jun 18, 2026
…rom 3.37.0 to 3.38.0 [skip ci]

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

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

> 3.38.0
> ------
>
> What's Changed
> --------------
>
> * Don't add MockitoExtension during migration when unsafe ([#875](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/875)) by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1017](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1017)
> * Add junit-platform-launcher testRuntimeOnly dependency for Gradle during JUnit 6 migration by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1018](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1018)
> * Migrate removed LocalStack Service enum and getEndpointOverride in Testcontainers 2.x migration by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1014](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1014)
> * Re-include CloseUnclosedStaticMocks in Mockito1to4Migration by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1019](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1019)
> * Update MockWebServer MockResponse test for nested-type render change by [`@​steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1020](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1020)
> * Fix UsesType precondition pattern in KotlinTestMethodsShouldReturnUnit by [`@​timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1022](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1022)
> * Support 4-arg Whitebox.setInternalState(target, field, value, Class) by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1023](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1023)
> * Refactor `PowerMockWhiteboxToJavaReflection` into per-API recipes by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1021](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1021)
> * Box primitive casts in `Whitebox.getInternalState`/`invokeMethod` reflection by [`@​MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1024](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1024)
>
> **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.37.0...v3.38.0>


Commits

* [`862bd49`](openrewrite/rewrite-testing-frameworks@862bd49) Box primitive casts in Whitebox getInternalState/invokeMethod reflection ([#1024](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1024))
* [`9e86af9`](openrewrite/rewrite-testing-frameworks@9e86af9) Refactor `PowerMockWhiteboxToJavaReflection` into per-API recipes ([#1021](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1021))
* [`30c392d`](openrewrite/rewrite-testing-frameworks@30c392d) Support 4-arg Whitebox.setInternalState(target, field, value, Class) ([#1023](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1023))
* [`c9cd3bd`](openrewrite/rewrite-testing-frameworks@c9cd3bd) Fix UsesType precondition pattern in KotlinTestMethodsShouldReturnUnit ([#1022](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1022))
* [`a602b44`](openrewrite/rewrite-testing-frameworks@a602b44) OpenRewrite recipe best practices
* [`ff368ff`](openrewrite/rewrite-testing-frameworks@ff368ff) Update UpdateMockWebServerMockResponse test for nested-type render change ([#1](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1)...
* [`45342dc`](openrewrite/rewrite-testing-frameworks@45342dc) Re-include CloseUnclosedStaticMocks in Mockito1to4Migration ([#1019](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1019))
* [`e1cb892`](openrewrite/rewrite-testing-frameworks@e1cb892) Migrate removed LocalStack `Service` enum and `getEndpointOverride` in Testco...
* [`3934d1e`](openrewrite/rewrite-testing-frameworks@3934d1e) Add junit-platform-launcher testRuntimeOnly dependency for Gradle during JUni...
* [`d5554a9`](openrewrite/rewrite-testing-frameworks@d5554a9) Don't add MockitoExtension during migration when unsafe ([#875](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/875)) ([#1017](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1017))
* Additional commits viewable in [compare view](openrewrite/rewrite-testing-frameworks@v3.37.0...v3.38.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working recipe Recipe request test provided

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant