-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make @SpringMock work for beans with @Primary #1503
Make @SpringMock work for beans with @Primary #1503
Conversation
fixes spockframework#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.
spock-spring/src/main/java/org/spockframework/spring/mock/SpockMockPostprocessor.java
Outdated
Show resolved
Hide resolved
Could you also check if there are other relevant new additions that were made to |
…nces Additional assertions in new tests are commented as depepnding on whether tests are run with :test or :testCglib they either pass or fail with "org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures)" exception - one failure being CannotCreateMockException and the other one the actual context loading problem.
I found four bugfixes applied to the
Apart from them there were ~4 PRs with refactorings/code polishing. I'll port the fix for 29639 here. |
6bc8f6c
to
ddd2b4c
Compare
spock-spring/src/main/java/org/spockframework/spring/mock/SpockMockPostprocessor.java
Outdated
Show resolved
Hide resolved
...ring/src/test/groovy/org/spockframework/spring/mock/SpringBeanWithManyOrNoPrimarySpec.groovy
Outdated
Show resolved
Hide resolved
This change follows changes made in Spring Boot's MockitoPostProcessor.
Hi @leonard84 |
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix @konradczajka
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.