Skip to content

Only turn the WireMockRule field's @Rule into @RegisterExtension in UseWiremockExtension - #1218

Merged
timtebeek merged 1 commit into
mainfrom
tim/wiremock-rule-annotation-only
Oct 24, 2026
Merged

timtebeek merged 1 commit into
mainfrom
tim/wiremock-rule-annotation-only

Conversation

@timtebeek

Copy link
Copy Markdown
Member

UseWiremockExtension swapped org.junit.Rule for RegisterExtension across the whole file once it saw a new WireMockRule(..), so other rules in the same class were retyped too:

@Rule public WireMockRule wm = new WireMockRule(7001);
@Rule public TemporaryFolder tmp = new TemporaryFolder();

came out as @RegisterExtension public TemporaryFolder tmp, which Jupiter rejects at runtime. Within JUnit4to5Migration the recipe runs before TemporaryFolderToTempDir and TestRuleToTestInfo, so those then no longer recognised their fields. Now only the @Rule on a WireMockRule field becomes @RegisterExtension, and org.junit.Rule is only removed when nothing else uses it. Through JUnit4to5Migration, the folder now becomes @TempDir public File tmp.

This overlaps with #1191, which adds a second file-wide ChangeType in the same spot, for org.junit.ClassRule. That would hit the same problem for other class rules (e.g. a @ClassRule static TemporaryFolder). Once this is merged, #1191 could match @org.junit.ClassRule in the new visitVariableDeclarations alongside @Rule instead of queueing a ChangeType. Its classRuleBecomesStaticRegisteredExtension test should pass unchanged.

Fixes item B1 of #1211.

…` in `UseWiremockExtension`

`UseWiremockExtension` queued a file-wide `ChangeType` from `org.junit.Rule` to `RegisterExtension` as soon as it saw a `new WireMockRule(..)`, so every other rule in the class was retyped too. A `@Rule TemporaryFolder tmp` next to the WireMock rule became `@RegisterExtension TemporaryFolder tmp`, which Jupiter rejects at runtime, and `TemporaryFolderToTempDir` and `TestRuleToTestInfo` later in `JUnit4to5Migration` no longer recognised those fields. Now only the `@Rule` on a `WireMockRule` field is replaced.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 24, 2026
@timtebeek
timtebeek merged commit 97996ce into main Oct 24, 2026
2 checks passed
@timtebeek
timtebeek deleted the tim/wiremock-rule-annotation-only branch October 24, 2026 11:51
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant