private static Class < ? > findTypeFromGeneric ( final InvocationOnMock invocation , final TypeVariable returnType ) { // Class level final MockCreationSettings mockSettings = MockUtil . getMockHandler ( invocation . getMock ( ) ) . getMockSettings ( ) ; final GenericMetadataSupport returnTypeSupport = GenericMetadataSupport . inferFrom ( mockSettings . getTypeToMock ( ) ) . resolveGenericReturnType ( invocation . getMethod ( ) ) ; final Class < ? > rawType = returnTypeSupport . rawType ( ) ; // Method level if ( rawType == Object . class ) { return findTypeFromGenericInArguments ( invocation , returnType ) ; } return rawType ; }
Retrieve the expected type when it came from a primitive . If the type cannot be retrieve return null .