question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add option to @InjectMock/QuarkusMock.installMock() services with Generics

See original GitHub issue

Description 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:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
famodcommented, Oct 16, 2020

/cc @geoand

1reaction
geoandcommented, Jun 15, 2021

This fell off my radar completely.

I’ll try and have a look for 2.1

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found