### Question:
GenericTypes { public static Optional<Type> findGenericParameter(Type type, Class<?> parameterizedSupertype) { return findGenericParameter(type, parameterizedSupertype, 0); } 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 findGenericParameterOfRaw() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Foo.class, "raw"), Foo.class)).isEqualTo(empty()); }
@Test public void findGenericParameterOfGeneric() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Foo.class, "generic"), Foo.class)) .contains(String.class); }
@Test public void findGenericParameterOfNestedGeneric() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Foo.class, "nestedGeneric"), Foo.class)) .contains(methodReturnType(Foo.class, "generic")); }
@Test public void findGenericParameterOfSuperClass() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Bar.class, "subTypeGeneric"), Foo.class)) .isEqualTo(Optional.of(Integer.class)); }
@Test public void findGenericParameterOfAncestorClass() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Baz.class, "descendentTypeGeneric"), Foo.class)) .contains(String.class); }
@Test public void findMultipleGenericParameters() throws NoSuchMethodException { assertThat(GenericTypes.findGenericParameter(methodReturnType(Xyz.class, "sample"), Xyz.class, 0)) .contains(String.class); assertThat(GenericTypes.findGenericParameter(methodReturnType(Xyz.class, "sample"), Xyz.class, 1)) .contains(Integer.class); assertThat(GenericTypes.findGenericParameter(methodReturnType(Xyz.class, "sample"), Xyz.class, 2)) .contains(Void.class); }