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
I encountered an issue with JUnit5/Mockito when using @Spy annotation with generic types.
Such configuration seems to break existing spies of Java record instances (inline mocks). The issue also occurs when using Mockito.spy() directly instead of the @Spy annotation. Example:
@ExtendWith(MockitoExtension.class)
classGenericSpyFailingTest {
// Removing this spy makes the test pass.@SpyprivatefinalList<String> genericSpy = List.of("item A", "item B");
@SpyprivateExampleRecordexampleRecord = newExampleRecord("some value");
@TestvoidexampleServiceUsesDependency() {
// The mocked record has all attributes set to null// despite being explicitly defined.assertNotNull(exampleRecord.someParameter());
}
}
Any idea why this happens? I couldn't find any mention of limitations related to using @Spy with generics.
This was originally encountered while using mockito-inline and an older Mockito version, but it is also reproducible with the latest mockito-core, as shown in the linked repo.
Any help is appreciated!
The text was updated successfully, but these errors were encountered:
LeMikaelF
pushed a commit
to LeMikaelF/mockito
that referenced
this issue
Nov 20, 2023
Hello,
I encountered an issue with JUnit5/Mockito when using
@Spy
annotation with generic types.Such configuration seems to break existing spies of Java
record
instances (inline mocks). The issue also occurs when usingMockito.spy()
directly instead of the@Spy
annotation. Example:See the example repo with tests to reproduce.
Any idea why this happens? I couldn't find any mention of limitations related to using
@Spy
with generics.This was originally encountered while using
mockito-inline
and an older Mockito version, but it is also reproducible with the latestmockito-core
, as shown in the linked repo.Any help is appreciated!
The text was updated successfully, but these errors were encountered: