Skip to content

Match Mockito and JUnit code by type, and format only what changes - #1195

Merged
jkschneider merged 1 commit into
mainfrom
rewrite-run-check-fixes
Oct 17, 2026
Merged

jkschneider merged 1 commit into
mainfrom
rewrite-run-check-fixes

Conversation

@jkschneider

Copy link
Copy Markdown
Member

Found by new rewriteRun checks in rewrite-test, which rerun each test with the changed code respelled (a static import for a qualified call and the reverse, fully qualified type names) and fail a recipe that auto-formats a whole class.

Formatting only what changed:

  • AddMissingNested formats only the class header after adding @nested.
  • MockitoJUnitRunnerToExtension and MockitoJUnitRunnerSilentToExtension drop a whole-class format after JavaTemplate's addAnnotation.
  • UpdateMockWebServer formats only the @AfterEach method it changes.
  • ReplaceInitMockToOpenMock and MockitoWhenOnStaticToMockStatic drop their whole-class formats. MockitoUtils.separateAddedMembers keeps the blank line after an added field.

Matching by type:

  • MockitoWhenOnStaticToMockStatic finds the mocked class of a statically imported or fully qualified static call, and imports it.
  • RemoveEmptyTests matches @Test in any spelling.
  • RemoveDoNothingForDefaultMocks accepts Mockito.doNothing().
  • ThenThrowCheckedExceptionToRuntimeException handles a fully qualified exception class literal.

Two expectations no longer expect an untouched empty body {} to become {\n}. Three tests are added.

Found by new rewriteRun checks in rewrite-test, which rerun each test with the changed code respelled (a static import for a qualified call and the reverse, fully qualified type names) and fail a recipe that auto-formats a whole class.

Formatting only what changed:
- AddMissingNested formats only the class header after adding @nested.
- MockitoJUnitRunnerToExtension and MockitoJUnitRunnerSilentToExtension drop a whole-class format after JavaTemplate's addAnnotation.
- UpdateMockWebServer formats only the @AfterEach method it changes.
- ReplaceInitMockToOpenMock and MockitoWhenOnStaticToMockStatic drop their whole-class formats. MockitoUtils.separateAddedMembers keeps the blank line after an added field.

Matching by type:
- MockitoWhenOnStaticToMockStatic finds the mocked class of a statically imported or fully qualified static call, and imports it.
- RemoveEmptyTests matches `@Test` in any spelling.
- RemoveDoNothingForDefaultMocks accepts `Mockito.doNothing()`.
- ThenThrowCheckedExceptionToRuntimeException handles a fully qualified exception class literal.

Two expectations no longer expect an untouched empty body `{}` to become `{\n}`. Three tests are added.
@jkschneider
jkschneider merged commit ded6de0 into main Oct 17, 2026
@jkschneider
jkschneider deleted the rewrite-run-check-fixes branch October 17, 2026 03:49
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 17, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 17, 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