Using Asserts with IllegalArgumentException/IllegalStateException instead of ConfigurationException.
This commit is contained in:
@@ -24,10 +24,7 @@ import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.aggregator.MethodInvokingAggregator;
|
||||
import org.springframework.integration.aggregator.CompletionStrategy;
|
||||
import org.springframework.integration.aggregator.CompletionStrategyAdapter;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
@@ -38,11 +35,13 @@ public class CompletionStrategyAdapterTests {
|
||||
|
||||
private SimpleCompletionStrategy simpleCompletionStrategy;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
simpleCompletionStrategy = new SimpleCompletionStrategy();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTrueConvertedProperly() {
|
||||
CompletionStrategyAdapter adapter = new CompletionStrategyAdapter(new AlwaysTrueCompletionStrategy(),
|
||||
@@ -97,62 +96,62 @@ public class CompletionStrategyAdapterTests {
|
||||
Assert.assertTrue(adapter.isComplete(messages));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAdapterWithWrongMethodName() {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "methodThatDoesNotExist");
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidParameterTypeUsingMethodName() {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "invalidParameterType");
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testTooManyParametersUsingMethodName() {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "tooManyParameters");
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotEnoughParametersUsingMethodName() {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "notEnoughParameters");
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testListSubclassParameterUsingMethodName() {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "ListSubclassParameter");
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongReturnType() throws SecurityException, NoSuchMethodError {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, "wrongReturnType");
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidParameterTypeUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new MethodInvokingAggregator(simpleCompletionStrategy, simpleCompletionStrategy.getClass().getMethod(
|
||||
"invalidParameterType", String.class));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testTooManyParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, simpleCompletionStrategy.getClass().getMethod(
|
||||
"tooManyParameters", List.class, List.class));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotEnoughParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, simpleCompletionStrategy.getClass().getMethod(
|
||||
"notEnoughParameters", new Class[] {}));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testListSubclassParameterUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, simpleCompletionStrategy.getClass().getMethod(
|
||||
"ListSubclassParameter", new Class[] { LinkedList.class }));
|
||||
}
|
||||
|
||||
@Test(expected = ConfigurationException.class)
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWrongReturnTypeUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new CompletionStrategyAdapter(simpleCompletionStrategy, simpleCompletionStrategy.getClass().getMethod(
|
||||
"wrongReturnType", new Class[] { List.class }));
|
||||
@@ -175,6 +174,7 @@ public class CompletionStrategyAdapterTests {
|
||||
new MethodInvokingAggregator(simpleCompletionStrategy, method);
|
||||
}
|
||||
|
||||
|
||||
private static List<Message<?>> createListOfMessages() {
|
||||
List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
messages.add(new GenericMessage<String>("123"));
|
||||
@@ -213,8 +213,7 @@ public class CompletionStrategyAdapterTests {
|
||||
return messages.size() > messages.iterator().next().getHeaders().getSequenceSize();
|
||||
}
|
||||
|
||||
// Example for the case when completeness is checked on the structure of
|
||||
// the data
|
||||
// Example for the case when completeness is checked on the structure of the data
|
||||
public boolean checkCompletenessOnListOfStrings(List<String> messages) {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (String content : messages) {
|
||||
|
||||
@@ -24,9 +24,7 @@ import java.util.List;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.aggregator.Aggregator;
|
||||
import org.springframework.integration.aggregator.MethodInvokingAggregator;
|
||||
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
|
||||
@@ -44,8 +42,9 @@ public class MethodInvokingAggregatorTests {
|
||||
simpleAggregator = new SimpleAggregator();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAdapterWithNonParameterizedMessageListBasedMethod() {
|
||||
public void adapterWithNonParameterizedMessageListBasedMethod() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationOnNonParameterizedListOfMessages");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
@@ -54,7 +53,7 @@ public class MethodInvokingAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithWildcardParametrizedMessageBasedMethod() {
|
||||
public void adapterWithWildcardParameterizedMessageBasedMethod() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationOnListOfMessagesParametrizedWithWildcard");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
@@ -63,16 +62,16 @@ public class MethodInvokingAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithTypeParametrizedMessageBasedMethod() {
|
||||
public void adapterWithTypeParameterizedMessageBasedMethod() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationOnListOfMessagesParametrizedWithString");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals("123456789", returnedMessge.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPojoBasedMethod() {
|
||||
public void adapterWithPojoBasedMethod() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationOnListOfStrings");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
@@ -81,16 +80,16 @@ public class MethodInvokingAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithPojoBasedMethodReturningObject() {
|
||||
public void adapterWithPojoBasedMethodReturningObject() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationOnListOfStringsReturningLong");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessge = aggregator.aggregate(messages);
|
||||
Assert.assertTrue(simpleAggregator.isAggregationPerformed());
|
||||
Assert.assertEquals(123456789l, returnedMessge.getPayload());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAdapterWithVoidReturnType() {
|
||||
public void adapterWithVoidReturnType() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationWithNoReturn");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessage = aggregator.aggregate(messages);
|
||||
@@ -99,7 +98,7 @@ public class MethodInvokingAggregatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdapterWithNullReturn() {
|
||||
public void adapterWithNullReturn() {
|
||||
Aggregator aggregator = new MethodInvokingAggregator(simpleAggregator, "doAggregationWithNullReturn");
|
||||
List<Message<?>> messages = createListOfMessages();
|
||||
Message<?> returnedMessage = aggregator.aggregate(messages);
|
||||
@@ -107,68 +106,68 @@ public class MethodInvokingAggregatorTests {
|
||||
Assert.assertNull(returnedMessage);
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testAdapterWithWrongMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void adapterWithWrongMethodName() {
|
||||
new MethodInvokingAggregator(simpleAggregator, "methodThatDoesNotExist");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testInvalidParameterTypeUsingMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidParameterTypeUsingMethodName() {
|
||||
new MethodInvokingAggregator(simpleAggregator, "invalidParameterType");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testTooManyParametersUsingMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void tooManyParametersUsingMethodName() {
|
||||
new MethodInvokingAggregator(simpleAggregator, "tooManyParameters");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testNotEnoughParametersUsingMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void notEnoughParametersUsingMethodName() {
|
||||
new MethodInvokingAggregator(simpleAggregator, "notEnoughParameters");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testListSubclassParameterUsingMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void listSubclassParameterUsingMethodName() {
|
||||
new MethodInvokingAggregator(simpleAggregator, "ListSubclassParameter");
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testInvalidParameterTypeUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidParameterTypeUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new MethodInvokingAggregator(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"invalidParameterType", String.class));
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testTooManyParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void tooManyParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new MethodInvokingAggregator(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"tooManyParameters", List.class, List.class));
|
||||
}
|
||||
|
||||
@Test(expected=ConfigurationException.class)
|
||||
public void testNotEnoughParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void notEnoughParametersUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new MethodInvokingAggregator(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"notEnoughParameters", new Class[] {} ));
|
||||
}
|
||||
|
||||
@Test(expected= ConfigurationException.class)
|
||||
public void testListSubclassParameterUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void listSubclassParameterUsingMethodObject() throws SecurityException, NoSuchMethodException {
|
||||
new MethodInvokingAggregator(simpleAggregator, simpleAggregator.getClass().getMethod(
|
||||
"listSubclassParameter", new Class[] {LinkedList.class} ));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullObject() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nullObject() {
|
||||
new MethodInvokingAggregator(null, "doesNotMatter");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullMethodName() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nullMethodName() {
|
||||
String methodName = null;
|
||||
new MethodInvokingAggregator(simpleAggregator, methodName);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullMethodObject() {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void nullMethodObject() {
|
||||
Method method = null;
|
||||
new MethodInvokingAggregator(simpleAggregator, method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user