### Question:
ReflectionHelper { public static List<ClassTypePair> getTypeArgumentAndClass(final Type type) throws IllegalArgumentException { final Type[] types = getTypeArguments(type); if (types == null) { return Collections.emptyList(); } List<ClassTypePair> list = new ArrayList<>(); for (Type t : types) { list.add(new ClassTypePair(erasure(t), t)); } return list; } private  ReflectionHelper(); static Map<String, Property> getProperties(Class clazz, Type genericType); static List<ClassTypePair> getTypeArgumentAndClass(final Type type); @SuppressWarnings("unchecked") static Class<T> erasure(Type type); static Type[] getTypeArguments(Type type); static String getPrimitiveDefault(Class type); static List<Field> getAllFields(Class<?> cls);  }### Answer:
@Test public void testGetTypeArgumentAndClassUsingSimpleType() throws Exception { Method method1 = this.getClass().getMethod("method1", String.class); Method method2 = this.getClass().getMethod("method2", List.class); Method method3 = this.getClass().getMethod("method3", List.class); List<ClassTypePair> ctp1 = ReflectionHelper.getTypeArgumentAndClass(method1.getGenericParameterTypes()[0]); List<ClassTypePair> ctp2 = ReflectionHelper.getTypeArgumentAndClass(method2.getGenericParameterTypes()[0]); List<ClassTypePair> ctp3 = ReflectionHelper.getTypeArgumentAndClass(method3.getGenericParameterTypes()[0]); assertThat(ctp1).isEmpty(); assertThat(ctp2.get(0).rawClass()).isEqualTo(String.class); assertThat(ctp2.get(0).type().toString()).contains(String.class.getName()); assertThat(ctp3.get(0).rawClass()).isEqualTo(List.class); assertThat(ctp3.get(0).type().toString()).contains("List").contains("String"); }
@Test public void testGetTypeArgumentAndClassUsingWildcard() throws Exception { Method method1 = this.getClass().getMethod("wildcard", List.class); List<ClassTypePair> ctp1 = ReflectionHelper.getTypeArgumentAndClass(method1.getGenericParameterTypes()[0]); assertThat(ctp1.get(0).rawClass()).isEqualTo(String.class); assertThat(ctp1.get(0).type()).isInstanceOf(WildcardType.class); }
@Test public void testGetTypeArgumentAndClassUsingVariable() throws Exception { Method method1 = this.getClass().getMethod("var", List.class); List<ClassTypePair> ctp1 = ReflectionHelper.getTypeArgumentAndClass(method1.getGenericParameterTypes()[0]); assertThat(ctp1.get(0).rawClass()).isEqualTo(String.class); assertThat(ctp1.get(0).type()).isInstanceOf(TypeVariable.class); }
@Test public void testGetTypeArgumentAndClassUsingGenericArray() throws Exception { Method method1 = getMethod("array"); List<ClassTypePair> ctp1 = ReflectionHelper.getTypeArgumentAndClass(method1.getGenericParameterTypes()[0]); assertThat(ctp1.get(0).rawClass()).isEqualTo(String[].class); assertThat(ctp1.get(0).type()).isInstanceOf(GenericArrayType.class); }