antoinemeyer/mock-in-bean

Mocking a bean in a Spy does not always work

antoinemeyer opened this issue · 4 comments

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.

Will be fixed in #11 by dbb5bb8

has this been fixed?

Not yet in master. It's quite an edge case but will push a fix for it in the coming weeks.

Fixed in version boot2-v1.6.

Let me know if you still have issue