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

@@ -14,7 +14,7 @@
<i:channel id="in"/>
<i:service-activator input-channel="in" output-channel="out" method="move">
<i:service-activator input-channel="in" output-channel="out">
<bean class="org.mockito.Mockito" factory-method="mock">
<constructor-arg
value="org.springframework.integration.test.mockito.ServiceActivatorOnMockitoMockTests$SingleMethod"/>

View File

@@ -1,11 +1,26 @@
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.test.mockito;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageBuilder;
@@ -13,11 +28,10 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
* @author Iwein Fuld
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@Ignore//remove to reproduce INT-944
public class ServiceActivatorOnMockitoMockTests {
@Autowired @Qualifier("in")
@@ -27,7 +41,6 @@ public class ServiceActivatorOnMockitoMockTests {
PollableChannel out;
public static class SingleMethod {
@ServiceActivator
public String move(String s){return s;};
}

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);