-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Support for @InjectMock EntityManager
#40807
Comments
Oddly enough, I could not reproduce this problem in either For the former the test I added was: @QuarkusTest
public class MockTest {
@InjectMock
EntityManager em;
@Test
public void test() {
Fruit mockResponse = new Fruit();
mockResponse.setId(1);
mockResponse.setName("mock");
Mockito.when(em.find(Fruit.class, 1)).thenReturn(mockResponse);
Fruit fruit = em.find(Fruit.class, 1);
Assertions.assertEquals("mock", fruit.getName());
}
} For the latter it was essentially the same thing but using |
@geoand I think that in order to reproduce this, you need to mock a method whose return type is overloaded in |
Oh, you are right, adding:
surfaces the problem. Honestly, I don't think we can do much... |
Yeah I don't know if we can solve this either, but we might be able to forbid |
Or more generally forbid |
That's probably a good idea |
Description
While
@InjectMock Session
works fine to mock the Hibernate ORM session, oddly@InjectMock EntityManager
doesn't, even if a given test only usesEntityManager
(e.g. using Panache): any method you'll mock will fail because something expect you to use theSession
return type, even though you're mocking aEntityManager
object (see stracktrace near the bottom).This is a bit counter-intuitive, so we should probably look into either making
@InjectMock EntityManager
work correctly, or documenting the limitation and adding clear exception messages when someone tries to do@InjectMock EntityManager
("@InjectMock
doesn't work withEntityManager
, useSession
instead").Stacktrace from: #40475 (comment)
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: