Skip to content

@MockBean leads to Mockito Validation Exceptions presumably masking problems with @Async annotated services #6573

Closed
@WalternativE

Description

@WalternativE

Hello everyone,

I have been experimenting with the Mockito integration in the new 1.4.0.RELEASE version of spring boot and encountered some difficulties while writing some tests.

I wrote a controller, which injects a service bean and calls an async method (async configuration is written to return a ThreadPoolTaskExecutor). When using the @MockBean annotation on the service in my test class all usages of parameter matchers fail (either while configuring in before method using given/willReturn or while verifying method calls).

I wrote a basic project illustrating this behavior - it can be found at https://github.com/WalternativE/mocking-bug . The tag "problem" contains the failing test while the tag "workaround" contains the profile configuration deactivating the async configuration for the test (the test passes without exception).

While researching the errors I stumbled upon issue #6405 - could be linked to that to some extend. I tried playing around with the proxyTargetClass parameter but I had no luck there.

While debugging the test cases I got the expected behavior while inspecting the mocked service with the IntelliJ Idea debugging tools - might have resolved some proxies manually which maybe cannot be resolved reflectively by Mockito (but that's just guesswork - haven't had the opportunity to reproduce that yet).

Thanks,
Gregor

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions