Visitar URL original
Fixes #2740 : Add mockMaker option to @Spy annotation by mirkoalicastro · Pull Request #3835 · mockito/mockito · GitHub
Skip to content

Fixes #2740 : Add mockMaker option to @Spy annotation - #3835

Merged
raphw merged 1 commit into
mockito:mainfrom
mirkoalicastro:feature/spy-annotation-mock-maker
Jun 21, 2026
Merged

raphw merged 1 commit into
mockito:mainfrom
mirkoalicastro:feature/spy-annotation-mock-maker

Conversation

@mirkoalicastro

Copy link
Copy Markdown
Contributor

Spy had no way to select a MockMaker per field, so the annotation-based spies always used the globally configured maker. Mock supports mockMaker since 4.8.0, so this PR closes that gap by implementing the same for Spy.

In addition to that, removing TODOs coming from the duplication of the spy-creation logic, extracted into SpyAnnotationUtil.

Example

@Spy(mockMaker = MockMakers.SUBCLASS) Foo spyOnFoo = new Foo("arg");

Fixes #2740

Checklist

  • Read the contributing guide
  • PR should be motivated, i.e. what does it fix, why, and if relevant how
  • If possible / relevant include an example in the description, that could help all readers
    including project members to get a better picture of the change
  • Avoid other runtime dependencies
  • Meaningful commit history ; intention is important please rebase your commit history so that each
    commit is meaningful and help the people that will explore a change in 2 years
  • The pull request follows coding style (run ./gradlew spotlessApply for auto-formatting)
  • Mention Fixes #<issue number> in the description if relevant
  • At least one commit should end with Fixes #<issue number> if relevant

@codecov-commenter

codecov-commenter commented Jun 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.84%. Comparing base (4ff92d9) to head (25c4d59).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3835      +/-   ##
============================================
- Coverage     86.84%   86.84%   -0.01%     
- Complexity     3042     3044       +2     
============================================
  Files           343      344       +1     
  Lines          9175     9172       -3     
  Branches       1136     1135       -1     
============================================
- Hits           7968     7965       -3     
  Misses          917      917              
  Partials        290      290              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@raphw

raphw commented Jun 21, 2026

Copy link
Copy Markdown
Member

Good catch, and looks good to me.

@raphw
raphw merged commit d6cb323 into mockito:main Jun 21, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add option to specify mockmaker for @Spy

3 participants