Make @SpringMock work for beans with @Primary
fixes #1502
When the context contains multiple beans for given interface but one of them is marked as @Primary it should be possible to mock this interface.
Current implementation doesn't check if one of found beans is primary and fails with an exception.
My change mirrors a similar logic used in spring-boot-starter-test and resolves this issue.
Could you also check if there are other relevant new additions that were made to MockitoPostProcessor that are missing in SpockMockPostProcessor?
Could you also check if there are other relevant new additions that were made to MockitoPostProcessor that are missing in SpockMockPostProcessor?
I found four bugfixes applied to the MockitoPostProcessor that seems to be missing in the SpockMockPostProcessor. One of them had been reverted later as it caused other problems. That leaves those three:
- 29639, which can and probably should be ported
- 27693, which probably is not important as
@Repeatis not used in Spock's specifications and other ways of running given test multiple times (e.g.@Unroll("#i")withwhere: i << (1..10)) don't seem to be affected by this problem. - 20665, which I was unable to reproduce with Spock. Mostly because
@SpringBeancannot be applied in the@Configurationclasses (usingDetachedMockFactorydoesn't trigger the bug).
Apart from them there were ~4 PRs with refactorings/code polishing.
I'll port the fix for 29639 here.
Hi @leonard84 Is there anything else you'd like to be changed in this PR or can it be merged?
Codecov Report
Merging #1503 (27bc768) into master (016c948) will increase coverage by
0.04%. The diff coverage is85.71%.
@@ Coverage Diff @@
## master #1503 +/- ##
============================================
+ Coverage 79.76% 79.81% +0.04%
- Complexity 4047 4051 +4
============================================
Files 412 412
Lines 12779 12795 +16
Branches 1652 1656 +4
============================================
+ Hits 10193 10212 +19
+ Misses 1988 1985 -3
Partials 598 598
| Impacted Files | Coverage Δ | |
|---|---|---|
| ...kframework/spring/mock/SpockMockPostprocessor.java | 88.34% <85.71%> (+3.30%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.