You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Mock for dependent list is created but not injected into entity #2637
IntelliJ IDEA version - Community 2023.2
Project - Maven
JDK - 17
Additional context
When debugging, linkedListSpy is returning expected values.
There is pet returning isNew()=false and getId()=0.
But owner.getPets() returns empty list.
There is no obvious reasons why Spring cannot inject this Spy into the instance under test. It can be manually fixed if we replace ArrayList with ArrayList<Pet>, but we cannot generate such code due to generics support limitations in UnitTestBot.
Tomorrow I'm going to ask other collegues if they see the reasons of autowiring problems here. If we clarify it, it may be possible to use some fallback as we do when there are several lists of one type in project.
@SPY annotation was constructed as a smart syntax and guidelines recommend it. After that, here we know one seldom bug, I have no idea how many potential problems are hidden in it. It can be investigated, but it will take time.
Activity
EgorkaKulikov commentedon Oct 3, 2023
Investigated with @tepa46 and @Vassiliy-Kudryashov - looks like a very strange case.
There is no obvious reasons why Spring cannot inject this Spy into the instance under test. It can be manually fixed if we replace
ArrayListwithArrayList<Pet>, but we cannot generate such code due to generics support limitations in UnitTestBot.Tomorrow I'm going to ask other collegues if they see the reasons of autowiring problems here. If we clarify it, it may be possible to use some fallback as we do when there are several lists of one type in project.
EgorkaKulikov commentedon Oct 4, 2023
It seems to be a bug in Mockito.
Consider the following test
This version does not work
This version works
However, in accordance with
@Spydocumentation, it must be the same.Seems to be a generics support problems in
@InjectMocks. There are some other known issues about it, like mockito/mockito#1066.alisevych commentedon Oct 4, 2023
@EgorkaKulikov
Can we generate code like it is in your second example?
With explicit spy creation?
EgorkaKulikov commentedon Oct 4, 2023
@SPY annotation was constructed as a smart syntax and guidelines recommend it. After that, here we know one seldom bug, I have no idea how many potential problems are hidden in it. It can be investigated, but it will take time.