### Question:
GenericTypes { public static Type resolveType(Type type, Type contextType) { return GenericTypeReflector.resolveType(type, contextType); } private  GenericTypes(); static Class<?> getErasedType(Type type); static Optional<Type> findGenericParameter(Type type, Class<?> parameterizedSupertype); static Optional<Type> findGenericParameter(Type type, Class<?> parameterizedSupertype, int n); static Type resolveType(Type type, Type contextType); static boolean isArray(Type type); static Type arrayType(Type type); static Type resolveMapEntryType(Type mapType); static Type resolveMapEntryType(Type keyType, Type valueType); static Type parameterizeClass(Class<?> clazz, Type... arguments); static Type box(Type type);  }### Answer:
@Test public void resolveType() throws NoSuchMethodException { abstract class A<T> { abstract T a(); } abstract class B extends A<String> {} assertThat(GenericTypes.resolveType(A.class.getDeclaredMethod("a").getGenericReturnType(), B.class)) .isEqualTo(String.class); }
@Test public void resolveTypeUnrelatedContext() throws NoSuchMethodException { abstract class A1<T> { abstract T a(); } abstract class A2<T> { abstract T a(); } abstract class B extends A2<String> {} Type t = A1.class.getDeclaredMethod("a").getGenericReturnType(); assertThat(GenericTypes.resolveType(t, B.class)).isEqualTo(t); }