INT-682, added no-arg method support for handlers, removed assertion for no-arg handler methods in HandlerMethodUtils and StaticHandlerMethodResolver, fixed test cases
This commit is contained in:
@@ -30,6 +30,7 @@ import org.springframework.integration.annotation.Headers;
|
||||
* Utility methods for common behavior related to Message-handling methods.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
abstract class HandlerMethodUtils {
|
||||
|
||||
@@ -47,9 +48,6 @@ abstract class HandlerMethodUtils {
|
||||
return false;
|
||||
}
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
if (parameterTypes.length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (parameterTypes.length > 1) {
|
||||
// at most one parameter can be lacking @Header or @Headers
|
||||
boolean foundPayloadParam = false;
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
|
||||
* or otherwise resolvable in advance based on static metadata.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class StaticHandlerMethodResolver implements HandlerMethodResolver {
|
||||
|
||||
@@ -35,8 +36,6 @@ public class StaticHandlerMethodResolver implements HandlerMethodResolver {
|
||||
|
||||
public StaticHandlerMethodResolver(Method method) {
|
||||
Assert.notNull(method, "method must not be null");
|
||||
Assert.notEmpty(method.getParameterTypes(),
|
||||
"Message-handling method [" + method + "] must accept at least one parameter.");
|
||||
Assert.isTrue(HandlerMethodUtils.isValidHandlerMethod(method),
|
||||
"Invalid Message-handling method [" + method + "]");
|
||||
this.method = method;
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MethodInvokingSelectorTests {
|
||||
|
||||
@@ -60,13 +61,13 @@ public class MethodInvokingSelectorTests {
|
||||
assertFalse(selector.accept(new GenericMessage<Integer>(99)));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void noArgMethodWithMethodName() {
|
||||
MethodInvokingSelector selector = new MethodInvokingSelector(new TestBean(), "noArgs");
|
||||
selector.accept(new StringMessage("test"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void noArgMethodWithMethodReference() throws Exception {
|
||||
TestBean testBean = new TestBean();
|
||||
Method method = testBean.getClass().getMethod("noArgs", new Class[] {});
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class StaticHandlerMethodResolverTests {
|
||||
|
||||
@@ -37,7 +38,7 @@ public class StaticHandlerMethodResolverTests {
|
||||
new StaticHandlerMethodResolver(method);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void noArgMethodIsNotValid() throws Exception {
|
||||
Method method = TestBean.class.getDeclaredMethod("noArgMethod", new Class<?>[0]);
|
||||
new StaticHandlerMethodResolver(method);
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.integration.util.TestUtils.TestApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class MethodInvokingMessageHandlerTests {
|
||||
|
||||
@@ -46,9 +47,9 @@ public class MethodInvokingMessageHandlerTests {
|
||||
handler.handleMessage(new GenericMessage<String>("test"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void invalidMethodWithNoArgs() {
|
||||
new MethodInvokingMessageHandler(new TestSink(), "invalidMethodWithNoArgs");
|
||||
new MethodInvokingMessageHandler(new TestSink(), "validMethodWithNoArgs");
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
@@ -118,7 +119,7 @@ public class MethodInvokingMessageHandlerTests {
|
||||
public void validMethod(String s) {
|
||||
}
|
||||
|
||||
public void invalidMethodWithNoArgs() {
|
||||
public void validMethodWithNoArgs() {
|
||||
}
|
||||
|
||||
public String methodWithReturnValue(String s) {
|
||||
|
||||
Reference in New Issue
Block a user