Skip to content

Add regression tests for openMocks removal with @ExtendWith#932

Closed
timtebeek wants to merge 1 commit intomainfrom
tim/mockito-openmocks-regression-tests
Closed

Add regression tests for openMocks removal with @ExtendWith#932
timtebeek wants to merge 1 commit intomainfrom
tim/mockito-openmocks-regression-tests

Conversation

@timtebeek
Copy link
Member

Summary

  • Adds regression tests confirming that Mockito1to3Migration and JUnit4to5Migration correctly remove MockitoAnnotations.openMocks(this) when @ExtendWith(MockitoExtension.class) is added
  • Covers the scenario from moderneinc/customer-requests#2030 where both annotations cause double mock instantiation
  • Tests verify simple openMocks(), openMocks() with AutoCloseable field + close(), and JUnit 4→5 migration path

Test plan

  • All new tests pass on current code (behavior already works correctly)
  • All existing RemoveInitMocksIfRunnersSpecified tests pass
  • All existing AddMockitoExtensionIfAnnotationsUsed tests pass
  • All existing Mockito1to3Migration tests pass

Adds tests confirming that the Mockito1to3Migration and JUnit4to5Migration
recipe chains correctly remove MockitoAnnotations.openMocks(this) when
@ExtendWith(MockitoExtension.class) is added to a test class.

Covers the scenario from moderneinc/customer-requests#2030 where having both
@ExtendWith(MockitoExtension.class) and MockitoAnnotations.openMocks(this)
causes double mock instantiation. Tests verify:

- Simple openMocks() call in @beforeeach is removed
- openMocks() with AutoCloseable field and close() in @AfterEach is removed
- JUnit 4 to 5 migration path with openMocks() works end-to-end
@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Mar 18, 2026
@timtebeek timtebeek closed this Mar 18, 2026
@github-project-automation github-project-automation bot moved this from In Progress to Done in OpenRewrite Mar 18, 2026
@timtebeek timtebeek deleted the tim/mockito-openmocks-regression-tests branch March 18, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant