Skip to content

Implement MockitoJUnitRunner to Extension Recipe - #709

Merged
sambsnyd merged 2 commits into
openrewrite:mainfrom
amishra-u:mockito
Apr 22, 2025
Merged

sambsnyd merged 2 commits into
openrewrite:mainfrom
amishra-u:mockito

Conversation

@amishra-u

Copy link
Copy Markdown
Contributor

What's changed?

Created a Recipe to migrate MockitoJUnitRunner to MockitoExtension.

What's your motivation?

The previous implementation had few issues:

  1. It only handled lenient and warn modes, and incorrectly migrated warn mode to strict mode (while the default for MockitoJUnitRunner is warn, the default for MockitoExtension is strict).
  2. Mode-specific handling was split between imperative (for lenient) and declarative (for warn) recipes.

Changes

  1. Consolidated all mode-handling logic (strict, warn, and lenient) into a single imperative recipe.
  2. New recipe correctly maps warn mode to maintain expected behavior and also handled strict mode for MockitoJUnitRunner.
  3. Marked the previous imperative recipe as deprecated for backward compatibility instead of removing it.

Followup

I will create a followup PR to update the UseMockitoExtension declarative recipe to leverage this new recipe.

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 21, 2025
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@timtebeek
timtebeek self-requested a review April 21, 2025 07:26
@timtebeek timtebeek moved this from In Progress to Ready to Review in OpenRewrite Apr 21, 2025
@amishra-u

Copy link
Copy Markdown
Contributor Author

@timtebeek please take a look. Hoping this to be part of next release.

@timtebeek timtebeek added recipe Recipe request mockito labels Apr 22, 2025
@sambsnyd
sambsnyd merged commit 15905d7 into openrewrite:main Apr 22, 2025
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Apr 22, 2025
@sambsnyd

Copy link
Copy Markdown
Member

Thanks @amishra-u

@amishra-u
amishra-u deleted the mockito branch April 23, 2025 04:11
Snurppa added a commit to Snurppa/rewrite-testing-frameworks that referenced this pull request Jun 10, 2025
Following up [openrewrite#709](openrewrite#709).

Running the recipe on a class which uses [MockitoJUnitRunner.StrictStubs](https://www.javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/junit/MockitoJUnitRunner.StrictStubs.html),
results in `@RunWith(MockitoJUnitRunner.StrictStubs.class)` to be untouched.
This is mainly because that class is not registered with `new RunnerToExtension(...)`, secondly because the `Strictness` enum did not contain the class name.

Modified so that also StrictStubs class is recognized and mapped it as `STRICT_STUBS` runner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mockito recipe Recipe request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants