Mocking a bean in a Spy does not always work
antoinemeyer opened this issue · 4 comments
antoinemeyer commented
Sometimes works and sometimes does not because of the non-deterministic aspect of MockInBean / SpyInbean definition parsing.
- Works when the mock is created before the spy (because the spy will use the fields already injected into the bean).
- Does not work when the spy is created before the mock (because the mock will be injected inside the spring bean and not the spy).
This is because the Spy does not delegate to the original object but creates a copy (as documented in https://javadoc.io/doc/org.mockito/mockito-core/latest/org/mockito/Spy.html).
Could be fixed by also injecting mocks into spies.
antoinemeyer commented
fuesec commented
has this been fixed?
antoinemeyer commented
Not yet in master. It's quite an edge case but will push a fix for it in the coming weeks.
antoinemeyer commented
Fixed in version boot2-v1.6
.
Let me know if you still have issue