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
We are trying to update from Mockito 4.8.1 to 5.10.0 using Java 17. We now have Problems with the Spy annotation. It does not seem to have any effect. If we create a spy using the spy() method, the spy works just fine.
The Spy is not injected with InjectMocks. If I look in the IntelliJ debug, I can see, that the Type of the Variable is just "HashSet". With Mockito 4.8.1, the type was "HashSet$MockitoMock". Is the spy not injected properly, because it is not created correctly? It seems like it has no wrapper at all. But why does the spy() method work then? It also just says "HashSet" as type in debug mode. Did we miss something or is this actually a bug?
Correct me if I am mistaken but it could be related due to the change in @SPY annotation behavior after Mockito 3.4.0 version. I believe starting from Mockito 3.4.0 version when using the annotation, Mockito won't create a wrapper object, and the spy is just a reference to the real object. So to create a wrapper object, you will have to use Mockito.spy() and that is probably why you are also seeing this on your end as well. Therefore I think this is just due to the change in the behavior of the annotation rather than a bug if my thought process is correct.
We are trying to update from Mockito 4.8.1 to 5.10.0 using Java 17. We now have Problems with the Spy annotation. It does not seem to have any effect. If we create a spy using the spy() method, the spy works just fine.
The Spy is not injected with InjectMocks. If I look in the IntelliJ debug, I can see, that the Type of the Variable is just "HashSet". With Mockito 4.8.1, the type was "HashSet$MockitoMock". Is the spy not injected properly, because it is not created correctly? It seems like it has no wrapper at all. But why does the spy() method work then? It also just says "HashSet" as type in debug mode. Did we miss something or is this actually a bug?
Does not work:
Works:
4.8.1:
5.10.0:
The text was updated successfully, but these errors were encountered: