### Question:
ReflectionTools { public static Method findMethod(Class<?> clazz, String methodName, Object methodParam) { Method method = null; Class<?> methodParamClass = methodParam.getClass(); while (methodParamClass != null) { method = ReflectionUtils.findMethod(clazz, "visit", methodParamClass); if (method != null) { return method; } for (Class<?> interf : methodParamClass.getInterfaces()) { method = ReflectionUtils.findMethod(clazz, "visit", interf); if (method != null) { return method; } } methodParamClass = methodParamClass.getSuperclass(); } return null; } private  ReflectionTools(); static Method findMethod(Class<?> clazz, String methodName, Object methodParam);  }### Answer:
@Test public void find_VisitorA_VisitableFoo() { Class<?> clazz = VisitorA.class; Object param = new VisitableFoo(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, clazz, "visit", param.getClass()); }
@Test public void find_VisitorA_VisitableBar() { Class<?> clazz = VisitorA.class; Object param = new VisitableBar(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, clazz, "visit", param.getClass()); }
@Test public void find_VisitorB_VisitableFoo() { Class<?> clazz = VisitorB.class; Object param = new VisitableFoo(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, VisitorA.class, "visit", param.getClass()); }
@Test public void find_VisitorB_VisitableBar() { Class<?> clazz = VisitorB.class; Object param = new VisitableBar(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, VisitorB.class, "visit", param.getClass()); }
@Test public void find_VisitorB_VisitableCar() { Class<?> clazz = VisitorB.class; Object param = new VisitableCar(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, VisitorB.class, "visit", VisitableBar.class); }
@Test public void find_VisitorA_VisitableCar() { Class<?> clazz = VisitorA.class; Object param = new VisitableCar(); Method m = ReflectionTools.findMethod(clazz, "visit", param); assertMethod(m, VisitorA.class, "visit", VisitableBar.class); }