ReflectionUtils { @SuppressWarnings("rawtypes") public static Class inferParameterClass(Class clazz, String methodName) { Method[] methods = clazz.getMethods(); for (Method method : methods) { if (method.getName().equals(methodName) && !method.isBridge()) { Type[] types = method.getGenericParameterTypes(); for (Type type : types) { if (type instanceof Class && !((Class) type).isInterface()) { return (Class) type; } } } } return null; } private  ReflectionUtils(); @SuppressWarnings("rawtypes") static Class inferParameterClass(Class clazz, String methodName);  }
@Test public void testFailingInfer() { TestListener<TaskExecutionFailedEvent> victim = new TestListener<TaskExecutionFailedEvent>(); assertEquals(null, ReflectionUtils.inferParameterClass(victim.getClass(), "onEvent")); }
@Test public void testInfer() { SecondTestListener victim = new SecondTestListener(); assertEquals(PercentageOfWorkDoneChangedEvent.class, ReflectionUtils.inferParameterClass(victim.getClass(), "onEvent")); }