Merge pull request #792 from garyrussell/INT-2972

* INT-2972: FixedMethodFilter - Return Mutable List
This commit is contained in:
Mark Fisher
2013-05-07 10:42:40 -04:00
2 changed files with 26 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.util;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -28,8 +29,9 @@ import org.springframework.util.Assert;
* the same Method instance within a single-element list if it is
* present in the candidate list. If the Method is not present
* in the candidate list, it will return an empty list.
*
*
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
public class FixedMethodFilter implements MethodFilter {
@@ -45,7 +47,9 @@ public class FixedMethodFilter implements MethodFilter {
public List<Method> filter(List<Method> methods) {
if (methods != null && methods.contains(this.method)) {
return Collections.singletonList(this.method);
List<Method> filteredList = new ArrayList<Method>(1);
filteredList.add(this.method);
return filteredList;
}
return Collections.<Method>emptyList();
}

View File

@@ -28,10 +28,11 @@ import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Rule;
import org.junit.Test;
import org.hamcrest.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.annotation.Header;
@@ -300,6 +301,15 @@ public class MethodInvokingMessageProcessorTests {
assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}
@Test
public void testProcessMessageMethodNotFound() throws Exception {
expected.expect(new ExceptionCauseMatcher(SpelEvaluationException.class));
TestDifferentErrorService service = new TestDifferentErrorService();
Method method = TestErrorService.class.getMethod("checked", String.class);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
processor.processMessage(new GenericMessage<String>("foo"));
}
@Test
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
@@ -348,7 +358,7 @@ public class MethodInvokingMessageProcessorTests {
private static class ExceptionCauseMatcher extends TypeSafeMatcher<Exception> {
private Throwable cause;
private Class<? extends Exception> type;
private final Class<? extends Exception> type;
public ExceptionCauseMatcher(Class<? extends Exception> type) {
this.type = type;
@@ -378,6 +388,13 @@ public class MethodInvokingMessageProcessorTests {
}
}
@SuppressWarnings("unused")
private static class TestDifferentErrorService {
public String checked(String input) throws Exception {
throw new CheckedException("Expected test exception");
}
}
@SuppressWarnings("serial")
public static final class CheckedException extends Exception {
public CheckedException(String string) {