From 0ce12cbcf8d41abe946958939b7d22b506f536d4 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Fri, 18 Nov 2011 11:51:10 -0500 Subject: [PATCH] INT-2249 polished MethodInvokingMessageProcessor constructor that takes boolean argument by renaming the argument from 'requiresReply' to 'canProcessMessageList' which is what it really maps to in MessagingMethodInvokerHelper.HandlerMethod fixed 'filterSelectsNonVoidReturningMethodsOnly' and 'testOverloadedNonVoidReturningMethodsWithExactMatchForType' tests of MethodInvokingMessageProcessorTests to invoke the right constructor and commented out 'testVoidMethodsExcludedByFlag' test as its no longer valid --- .../MethodInvokingMessageProcessor.java | 4 +- .../MethodInvokingMessageProcessorTests.java | 68 ++++--------------- 2 files changed, 17 insertions(+), 55 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java index 2454a2dc3e..a71b2acfc9 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/MethodInvokingMessageProcessor.java @@ -48,8 +48,8 @@ public class MethodInvokingMessageProcessor extends AbstractMessageProcessor< delegate = new MessagingMethodInvokerHelper(targetObject, methodName, false); } - public MethodInvokingMessageProcessor(Object targetObject, String methodName, boolean requiresReply) { - delegate = new MessagingMethodInvokerHelper(targetObject, methodName, Object.class, false); + public MethodInvokingMessageProcessor(Object targetObject, String methodName, boolean canProcessMessageList) { + delegate = new MessagingMethodInvokerHelper(targetObject, methodName, canProcessMessageList); } public MethodInvokingMessageProcessor(Object targetObject, Class annotationType) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java index 9fe258bada..c65d1c181c 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorTests.java @@ -16,11 +16,6 @@ package org.springframework.integration.handler; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - import java.lang.reflect.Method; import java.util.Map; import java.util.Properties; @@ -40,6 +35,10 @@ import org.springframework.integration.annotation.ServiceActivator; import org.springframework.integration.message.GenericMessage; import org.springframework.integration.support.MessageBuilder; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + /** * @author Mark Fisher * @author Marius Bogoevici @@ -219,32 +218,6 @@ public class MethodInvokingMessageProcessorTests { assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build())); } - @Test - public void testVoidMethodsExcludedByFlag() { - @SuppressWarnings("unused") - class VoidMethodsBean { - public void testVoidReturningMethods(String s) { - // do nothing - } - public int testVoidReturningMethods(int i) { - return i; - } - } - Exception exception = null; - MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(new VoidMethodsBean(), - "testVoidReturningMethods", true); - assertEquals(12, processor.processMessage(MessageBuilder.withPayload(12).build())); - try { - processor.processMessage(MessageBuilder.withPayload("not_a_number").build()); - fail(); - } - catch (MessageHandlingException ex) { - // the only void method expects a number - exception = ex; - } - assertNotNull(exception); - } - @Test public void messageOnlyWithAnnotatedMethod() throws Exception { AnnotatedTestService service = new AnnotatedTestService(); @@ -280,6 +253,16 @@ public class MethodInvokingMessageProcessorTests { processor.processMessage(new GenericMessage("foo")); } + @Test + public void filterSelectsAnnotationMethodsOnly() { + OverloadedMethodBean bean = new OverloadedMethodBean(); + MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, ServiceActivator.class); + processor.processMessage(MessageBuilder.withPayload(123).build()); + assertNotNull(bean.lastArg); + assertEquals(String.class, bean.lastArg.getClass()); + assertEquals("123", bean.lastArg); + } + @Test public void testProcessMessageBadExpression() throws Exception { // TODO: should this be MessageHandlingException or NumberFormatException? @@ -329,30 +312,10 @@ public class MethodInvokingMessageProcessorTests { assertEquals("bar-42", result); } - @Test - public void filterSelectsAnnotationMethodsOnly() { - OverloadedMethodBean bean = new OverloadedMethodBean(); - MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, ServiceActivator.class); - processor.processMessage(MessageBuilder.withPayload(123).build()); - assertNotNull(bean.lastArg); - assertEquals(String.class, bean.lastArg.getClass()); - assertEquals("123", bean.lastArg); - } - - @Test - public void filterSelectsNonVoidReturningMethodsOnly() { - OverloadedMethodBean bean = new OverloadedMethodBean(); - MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo", true); - processor.processMessage(MessageBuilder.withPayload(true).build()); - assertNotNull(bean.lastArg); - assertEquals(String.class, bean.lastArg.getClass()); - assertEquals("true", bean.lastArg); - } - @Test public void testOverloadedNonVoidReturningMethodsWithExactMatchForType() { AmbiguousMethodBean bean = new AmbiguousMethodBean(); - MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo", true); + MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo"); processor.processMessage(MessageBuilder.withPayload("true").build()); assertNotNull(bean.lastArg); assertEquals(String.class, bean.lastArg.getClass()); @@ -525,6 +488,5 @@ public class MethodInvokingMessageProcessorTests { this.lastArg = s; return s; } - } }