Add option to @InjectMock/QuarkusMock.installMock() services with Generics
See original GitHub issueDescription
Currently it is not possible to use @InjectMock
with services with generic interface. For example check this case:
https://github.com/asodja/quarkus-generic-mock/blob/master/src/test/java/org/my/group/MyResourceTest.java
When running test you get:
Caused by: java.lang.IllegalStateException: Invalid use of io.quarkus.test.junit.mockito.InjectMock - could not determine bean of type: interface org.my.group.service.Service. Offending field is service of test class class org.my.group.MyResourceTest
at io.quarkus.test.junit.mockito.internal.CreateMockitoMocksCallback.getBeanInstance(CreateMockitoMocksCallback.java:61)
at io.quarkus.test.junit.mockito.internal.CreateMockitoMocksCallback.afterConstruct(CreateMockitoMocksCallback.java:27)
To workaround this you have to use rawtypes everywhere (also in production code) which is not nice.
It would be great if there is some way of Injecting Mocks for services that use generics.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to register dependency injection with generic types? (.net ...
I would like to create an extension method to generate the injection. Here is what I would like to do: using Microsoft.Extensions.Configuration; ...
Read more >Generic Methods - Java™ Tutorials
This Java tutorial describes generics, full screen mode API, and Java certification related resources.
Read more >ASP.NET Core Dependency Injection - Code with Steve
A short post exploring how generic types can be registered with the Microsoft Dependency Injection container provided with ASP.NET Core.
Read more >Registering Open Generics in ASPNET Core Dependency ...
NET Core startup, there is a simple way to do so. If you only use the generic methods for adding services, such as:...
Read more >Java Generics Example Tutorial - Generic Method, Class ...
Generics was added in Java 5 to provide compile-time type checking ... GenericsTypeOld { private Object t; public Object get() { return t;...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
/cc @geoand
This fell off my radar completely.
I’ll try and have a look for
2.1