Skip to content

Commit

Permalink
mockito#2921 maintain generic type info for spys as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Jörg von Frantzius committed Feb 27, 2023
1 parent adc5933 commit 4552850
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private static Object spyInstance(Field field, Object instance) {
return Mockito.mock(
instance.getClass(),
withSettings()
.genericTypeToMock(field.getGenericType())
.spiedInstance(instance)
.defaultAnswer(CALLS_REAL_METHODS)
.name(field.getName()));
Expand All @@ -96,7 +97,10 @@ private static Object spyNewInstance(Object testInstance, Field field)
throws InstantiationException, IllegalAccessException, InvocationTargetException {
// TODO: Add mockMaker option for @Spy annotation (#2740)
MockSettings settings =
withSettings().defaultAnswer(CALLS_REAL_METHODS).name(field.getName());
withSettings()
.genericTypeToMock(field.getGenericType())
.defaultAnswer(CALLS_REAL_METHODS)
.name(field.getName());
Class<?> type = field.getType();
if (type.isInterface()) {
return Mockito.mock(type, settings.useConstructor());
Expand Down

0 comments on commit 4552850

Please sign in to comment.