-
Notifications
You must be signed in to change notification settings - Fork 41.1k
@MockBean does not handle parameterized types #6602
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
Comments
I had a quick look but I think we might need some updates to Spring's Currently I don't think we have a way to programmatically register a bean definition with a specific @jhoeller am I correct with this assumption? Would adding support be something we'd consider in a point release? |
@rocketraman You may be able to work around this issue in the meantime by specifying the specific bean names to replace when you declare your mocks. Something like: @MockBean(name = "passwordIdentityProvider")
private IdentityProvider<PasswordIdentity> passwordIdentityProvider;
@MockBean(name = "oauth2IdentityProvider")
private IdentityProvider<Oauth2Identity> oauth2IdentityProvider; |
@philwebb Yes, I can confirm that workaround works (though I need to explicitly specify the |
@rocketraman Thanks for raising the issue. I'd like to provide better support for this but it may take some time since changes to Spring Framework are likely required. |
We could indeed consider some extra field on a bean definition that indicates a generic target type to specifically match instead of getting that information from the bean class or factory method. Looks doable for 4.3.3 still, simply sitting next to our existing target type field on a root bean definition and not used unless specifically set on registration. |
Related Spring Framework Issue : https://jira.spring.io/browse/SPR-14580 |
Fix is here https://github.com/philwebb/spring-boot/tree/gh-6602, just waiting for SPR-14580 to get merged. |
Spring Boot 1.4.0.RELEASE
I am trying to use the new
@MockBean
annotation to inject two mocks of the same parameterized interface, each with a different type i.e.:When running this test with
@SpringBootTest
I get the following error:Note that exposing two beans of these parameterized types works fine in the regular non-test Spring context i.e. the types are injected correctly by Spring.
In addition, I can create the mocks manually via Mockito, also correctly.
The text was updated successfully, but these errors were encountered: