Match MockWebServer.shutdown() against pre-rename type#1012
Merged
steve-aom-elliott merged 2 commits intoJun 2, 2026
Conversation
The ChangeMethodName step targeted `mockwebserver3.MockWebServer shutdown()` — the post-rename type — but ran before UpdateMockWebServerMockResponse performs the `okhttp3.mockwebserver` -> `mockwebserver3` ChangePackage. On the first cycle the pattern can't match (the call's declaring type is still the old `okhttp3.mockwebserver.MockWebServer`), so the rename only completes via a second iteration cycle. Targeting the pre-rename type lets the rename happen in a single cycle: shutdown() -> close() while the old types are still in scope, then UpdateMockWebServerMockResponse does the bulk package move at the end of the recipe.
a202d21 to
f4262ef
Compare
The Java parser fails to type-resolve method calls on `okhttp3.mockwebserver.MockWebServer` when the JUnit 4 `org.junit.rules.ExternalResource` supertype isn't on the parser classpath. Both 3.14 and 4.10 mockwebserver extend ExternalResource. The constructor still resolves without it (so simpler tests pass), but a method invocation like `server.shutdown()` ends up with a malformed declaring type. Mirrors the parser classpath used by sibling UpdateMockWebServerMockResponseTest.
f4262ef to
4e80957
Compare
mergify Bot
added a commit
to robfrank/linklift
that referenced
this pull request
Jun 4, 2026
…rom 3.35.2 to 3.37.0 [skip ci] Bumps [org.openrewrite.recipe:rewrite-testing-frameworks](https://github.com/openrewrite/rewrite-testing-frameworks) from 3.35.2 to 3.37.0. Release notes *Sourced from [org.openrewrite.recipe:rewrite-testing-frameworks's releases](https://github.com/openrewrite/rewrite-testing-frameworks/releases).* > 3.37.0 > ------ > > What's Changed > -------------- > > * Reuse `MockedStatic` for consecutive stubbings of the same class by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1005](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1005) > * Add RemoveJupiterMigrationSupport recipe by [`@sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#1006](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1006) > * Regenerate recipes.csv by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1007](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1007) > * fix: retain doNothing() stubs inside lambda bodies to prevent uncompilable code by [`@darrencilia`](https://github.com/darrencilia) in [openrewrite/rewrite-testing-frameworks#1009](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1009) > * Migrate deprecated AssertionsForClassTypes/InterfaceTypes to Assertions by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1010](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1010) > * Add direct mockwebserver3 dep when only inherited from parent pom by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1011](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1011) > * Match MockWebServer.shutdown() against pre-rename type by [`@steve-aom-elliott`](https://github.com/steve-aom-elliott) in [openrewrite/rewrite-testing-frameworks#1012](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1012) > > New Contributors > ---------------- > > * [`@darrencilia`](https://github.com/darrencilia) made their first contribution in [openrewrite/rewrite-testing-frameworks#1009](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1009) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.36.0...v3.37.0> > > 3.36.0 > ------ > > What's Changed > -------------- > > * Skip wrapper-primitive in `UseAssertSame`; rewrite via `AssertTrueComparisonToAssertEquals` by [`@motlin`](https://github.com/motlin) in [openrewrite/rewrite-testing-frameworks#995](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/995) > * Add unit test for JUnit6BestPractices by [`@sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#994](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/994) > * Cleanup junit vintage engine by [`@sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#993](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/993) > * OpenRewrite recipe best practices by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#997](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/997) > * Fix `JUnit4to5Migration` for classes that extend `org.junit.Assert` by [`@motlin`](https://github.com/motlin) in [openrewrite/rewrite-testing-frameworks#996](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/996) > * Preserve newlines when converting `@CsvSource(textBlock = ...)` to `@ValueSource` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#998](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/998) > * Fix `EnclosedToNested` failing with "Expected to find enclosing JavaSourceFile" by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1001](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1001) > * Fix `assertEquals` delta misinterpreted as message in AssertJ conversion by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1000](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1000) > * Add JUnit 6.1 migration recipes by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#1002](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1002) > * Handle Kotlin sources in `MockitoWhenOnStaticToMockStatic` by [`@MBoegers`](https://github.com/MBoegers) in [openrewrite/rewrite-testing-frameworks#1003](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/1003) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.35.3...v3.36.0> > > v3.35.3 > ------- > > What's Changed > -------------- > > * OpenRewrite [v8.81.6](https://github.com/openrewrite/rewrite/releases/tag/v8.81.6) > * Cleanup Mockito AutoCloseable fields by [`@sullis`](https://github.com/sullis) in [openrewrite/rewrite-testing-frameworks#977](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/977) > * Preserve mockStatic when returned from helper methods by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#979](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/979) > * Upgrade junit-bom to 6.x in JUnit 5 to 6 migration by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#978](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/978) > * Tighten PowerMockitoMockStaticToMockito precondition to actual PowerMockito usage by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#981](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/981) > * Fix AssertTrueInstanceofToAssertInstanceOf static import by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#984](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/984) > * Fix `ClassCastException` for `@PrepareForTest(fullyQualifiedNames = "...")` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#983](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/983) > * Preserve `doNothing()` stubbings using `ArgumentCaptor.capture()` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#988](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/988) > * Document strictness implication of `RemoveInitMocksIfRunnersSpecified` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#990](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/990) > * Support `textBlock` attribute in `CsvSourceToValueSource` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#989](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/989) > * Skip primitive comparisons in `UseAssertSame` by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-testing-frameworks#992](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/pull/992) > > **Full Changelog**: <openrewrite/rewrite-testing-frameworks@v3.35.2...v3.35.3> Commits * [`5b719c2`](openrewrite/rewrite-testing-frameworks@5b719c2) Extract documentation examples from tests * [`1ca6223`](openrewrite/rewrite-testing-frameworks@1ca6223) Match MockWebServer.shutdown() against pre-rename type ([#1012](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1012)) * [`9479988`](openrewrite/rewrite-testing-frameworks@9479988) Add direct mockwebserver3 dep when only old mockwebserver dep inherited from ... * [`4d31fbb`](openrewrite/rewrite-testing-frameworks@4d31fbb) Add recipe to migrate AssertionsForClassTypes/InterfaceTypes to Assertions (#... * [`7cbff2a`](openrewrite/rewrite-testing-frameworks@7cbff2a) OpenRewrite recipe best practices * [`86f2308`](openrewrite/rewrite-testing-frameworks@86f2308) fix: retain doNothing() stubs inside lambda bodies to prevent uncompilable co... * [`45d2528`](openrewrite/rewrite-testing-frameworks@45d2528) Update Gradle wrapper 9.5.1 * [`a632e17`](openrewrite/rewrite-testing-frameworks@a632e17) Regenerate recipes.csv ([#1007](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1007)) * [`0b192ca`](openrewrite/rewrite-testing-frameworks@0b192ca) Add RemoveJupiterMigrationSupport recipe ([#1006](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1006)) * [`f3f61a6`](openrewrite/rewrite-testing-frameworks@f3f61a6) Reuse `MockedStatic` for consecutive stubbings of the same class ([#1005](https://redirect.github.com/openrewrite/rewrite-testing-frameworks/issues/1005)) * Additional commits viewable in [compare view](openrewrite/rewrite-testing-frameworks@v3.35.2...v3.37.0)
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.
What
Changes the
ChangeMethodNamestep inUpgradeOkHttpMockWebServerto matchokhttp3.mockwebserver.MockWebServer shutdown()instead ofmockwebserver3.MockWebServer shutdown().Why
The step was placed before
UpdateMockWebServerMockResponse, which internally runsChangePackage("okhttp3.mockwebserver", "mockwebserver3", false). With the pattern targeting the post-rename type (mockwebserver3.MockWebServer), the method-call's declaring type at the timeChangeMethodNameruns is stillokhttp3.mockwebserver.MockWebServer— so the pattern doesn't match on the first cycle. OpenRewrite's iterative execution eventually completes the rename on a subsequent cycle, but it's an unnecessary cycle and the recipe reads in a confusing order (the pattern references a type that doesn't exist yet at that point).Targeting the pre-rename type lets the rename happen in a single cycle:
shutdown()→close()is applied while the old types are still in scope, thenUpdateMockWebServerMockResponse'sChangePackagedoes the bulk move tomockwebserver3.*at the end. The recipeList now reads top-to-bottom as a natural pipeline of source rewrites against the old types, followed by the package rename as a final cleanup step.Test
Added
shouldRenameShutdownToCloseAlongWithPackageChangetoUpgradeOkHttpMockWebServerTest. The fixture has a project with a directmockwebserver:4.10.0test-scope dep and a test source that importsokhttp3.mockwebserver.MockWebServerand callsserver.shutdown(). After the recipe runs the source should importmockwebserver3.MockWebServerand callserver.close().Marking draft until CI confirms.