INT-944 MethodInvokingMessageProcessor now handles Mockito mocks properly.

This commit is contained in:
Mark Fisher
2009-12-24 14:23:55 +00:00
parent ab7272d980
commit f65e47b41d
3 changed files with 35 additions and 7 deletions

View File

@@ -192,7 +192,8 @@ public class MethodInvokingMessageProcessor implements MessageProcessor {
final Map<Class<?>, HandlerMethod> candidateMethods = new HashMap<Class<?>, HandlerMethod>();
final Map<Class<?>, HandlerMethod> fallbackMethods = new HashMap<Class<?>, HandlerMethod>();
final AtomicReference<Class<?>> ambiguousFallbackType = new AtomicReference<Class<?>>();
ReflectionUtils.doWithMethods(targetObject.getClass(), new MethodCallback() {
Class<?> targetClass = this.getTargetClass(targetObject);
ReflectionUtils.doWithMethods(targetClass, new MethodCallback() {
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
boolean matchesAnnotation = false;
if (method.isBridge()) {
@@ -250,6 +251,20 @@ public class MethodInvokingMessageProcessor implements MessageProcessor {
return fallbackMethods;
}
private Class<?> getTargetClass(Object targetObject) {
Class<?> targetClass = targetObject.getClass();
if (AopUtils.isAopProxy(targetObject)) {
targetClass = AopUtils.getTargetClass(targetObject);
}
else if(AopUtils.isCglibProxyClass(targetClass)) {
Class<?> superClass = targetObject.getClass().getSuperclass();
if (!Object.class.equals(superClass)) {
targetClass = superClass;
}
}
return targetClass;
}
private List<HandlerMethod> findHandlerMethodsForMessage(Message<?> message) {
final Class<?> payloadType = message.getPayload().getClass();
HandlerMethod closestMatch = this.findClosestMatch(payloadType);