Browse Source

Polish spring-messsaging

- Removed unused imports
- Organized imports
- Discontinued use of deprecated junit.framework.Assert class
- Suppressed warnings where appropriate
- Added missing generics to return type for getMappingComparator() in
  SimpAnnotationMethodMessageHandler
pull/391/merge
Sam Brannen 11 years ago
parent
commit
bf9ec78c5d
  1. 11
      spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolver.java
  2. 2
      spring-messaging/src/main/java/org/springframework/messaging/handler/condition/AbstractMessageCondition.java
  3. 13
      spring-messaging/src/main/java/org/springframework/messaging/handler/condition/DestinationPatternsMessageCondition.java
  4. 25
      spring-messaging/src/main/java/org/springframework/messaging/simp/handler/SimpAnnotationMethodMessageHandler.java
  5. 10
      spring-messaging/src/main/java/org/springframework/messaging/support/tcp/ReactorTcpConnection.java
  6. 24
      spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/PathVariableMethodArgumentResolverTests.java
  7. 8
      spring-messaging/src/test/java/org/springframework/messaging/simp/handler/SimpMessageTypeMessageConditionTests.java
  8. 19
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java
  9. 5
      spring-messaging/src/test/java/org/springframework/messaging/support/channel/PublishSubscibeChannelTests.java

11
spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AnnotationExceptionHandlerMethodResolver.java

@ -17,16 +17,16 @@ @@ -17,16 +17,16 @@
package org.springframework.messaging.handler.annotation.support;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.core.ExceptionDepthComparator;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
import org.springframework.messaging.handler.method.AbstractExceptionHandlerMethodResolver;
import org.springframework.messaging.handler.method.HandlerMethodSelector;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils.MethodFilter;
@ -41,7 +41,6 @@ import org.springframework.util.ReflectionUtils.MethodFilter; @@ -41,7 +41,6 @@ import org.springframework.util.ReflectionUtils.MethodFilter;
*/
public class AnnotationExceptionHandlerMethodResolver extends AbstractExceptionHandlerMethodResolver {
/**
* A constructor that finds {@link MessageExceptionHandler} methods in the given type.
* @param handlerType the type to introspect

2
spring-messaging/src/main/java/org/springframework/messaging/handler/condition/AbstractMessageCondition.java

@ -16,8 +16,6 @@ @@ -16,8 +16,6 @@
package org.springframework.messaging.handler.condition;
import org.springframework.web.servlet.mvc.condition.RequestCondition;
import java.util.Collection;
import java.util.Iterator;

13
spring-messaging/src/main/java/org/springframework/messaging/handler/condition/DestinationPatternsMessageCondition.java

@ -16,15 +16,22 @@ @@ -16,15 +16,22 @@
package org.springframework.messaging.handler.condition;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.method.AbstractMethodMessageHandler;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Assert;
import org.springframework.util.PathMatcher;
import org.springframework.util.StringUtils;
import java.util.*;
/**
* A {@link MessageCondition} for matching the destination of a Message against one or
* more destination patterns using a {@link PathMatcher}.

25
spring-messaging/src/main/java/org/springframework/messaging/simp/handler/SimpAnnotationMethodMessageHandler.java

@ -17,7 +17,13 @@ @@ -17,7 +17,13 @@
package org.springframework.messaging.simp.handler;
import java.lang.reflect.Method;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
@ -28,9 +34,18 @@ import org.springframework.messaging.Message; @@ -28,9 +34,18 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.core.AbstractMessageSendingTemplate;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.support.*;
import org.springframework.messaging.handler.annotation.support.AnnotationExceptionHandlerMethodResolver;
import org.springframework.messaging.handler.annotation.support.HeaderMethodArgumentResolver;
import org.springframework.messaging.handler.annotation.support.HeadersMethodArgumentResolver;
import org.springframework.messaging.handler.annotation.support.MessageMethodArgumentResolver;
import org.springframework.messaging.handler.annotation.support.PathVariableMethodArgumentResolver;
import org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver;
import org.springframework.messaging.handler.condition.DestinationPatternsMessageCondition;
import org.springframework.messaging.handler.method.*;
import org.springframework.messaging.handler.method.AbstractExceptionHandlerMethodResolver;
import org.springframework.messaging.handler.method.AbstractMethodMessageHandler;
import org.springframework.messaging.handler.method.HandlerMethod;
import org.springframework.messaging.handler.method.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.method.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.messaging.simp.SimpMessagingTemplate;
@ -255,7 +270,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan @@ -255,7 +270,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
}
@Override
protected Comparator getMappingComparator(final Message<?> message) {
protected Comparator<SimpMessageMappingInfo> getMappingComparator(final Message<?> message) {
return new Comparator<SimpMessageMappingInfo>() {
@Override
public int compare(SimpMessageMappingInfo info1, SimpMessageMappingInfo info2) {
@ -292,4 +307,4 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan @@ -292,4 +307,4 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
return new AnnotationExceptionHandlerMethodResolver(beanType);
}
}
}

10
spring-messaging/src/main/java/org/springframework/messaging/support/tcp/ReactorTcpConnection.java

@ -16,20 +16,10 @@ @@ -16,20 +16,10 @@
package org.springframework.messaging.support.tcp;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.springframework.messaging.Message;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.util.concurrent.ListenableFutureCallbackRegistry;
import reactor.core.composable.Deferred;
import reactor.core.composable.Promise;
import reactor.core.composable.spec.DeferredPromiseSpec;
import reactor.function.Consumer;
public class ReactorTcpConnection<P> implements TcpConnection<P> {

24
spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/PathVariableMethodArgumentResolverTests.java

@ -28,7 +28,6 @@ import org.springframework.core.MethodParameter; @@ -28,7 +28,6 @@ import org.springframework.core.MethodParameter;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.annotation.PathVariable;
import org.springframework.messaging.simp.handler.SimpAnnotationMethodMessageHandler;
import org.springframework.messaging.support.MessageBuilder;
import static org.junit.Assert.*;
@ -45,12 +44,12 @@ public class PathVariableMethodArgumentResolverTests { @@ -45,12 +44,12 @@ public class PathVariableMethodArgumentResolverTests {
private MethodParameter paramAnnotatedValue;
private MethodParameter paramNotAnnotated;
@Before
public void setup() throws Exception {
this.resolver = new PathVariableMethodArgumentResolver(new DefaultConversionService());
Method method = getClass().getDeclaredMethod("handleMessage",
String.class, String.class, String.class);
Method method = getClass().getDeclaredMethod("handleMessage", String.class, String.class, String.class);
this.paramAnnotated = new MethodParameter(method, 0);
this.paramAnnotatedValue = new MethodParameter(method, 1);
this.paramNotAnnotated = new MethodParameter(method, 2);
@ -70,15 +69,15 @@ public class PathVariableMethodArgumentResolverTests { @@ -70,15 +69,15 @@ public class PathVariableMethodArgumentResolverTests {
@Test
public void resolveArgument() throws Exception {
Map<String,Object> pathParams = new HashMap<String,Object>();
pathParams.put("foo","bar");
pathParams.put("name","value");
Message<byte[]> message = MessageBuilder.withPayload(new byte[0])
.setHeader(PathVariableMethodArgumentResolver.PATH_TEMPLATE_VARIABLES_HEADER, pathParams).build();
Map<String, Object> pathParams = new HashMap<String, Object>();
pathParams.put("foo", "bar");
pathParams.put("name", "value");
Message<byte[]> message = MessageBuilder.withPayload(new byte[0]).setHeader(
PathVariableMethodArgumentResolver.PATH_TEMPLATE_VARIABLES_HEADER, pathParams).build();
Object result = this.resolver.resolveArgument(this.paramAnnotated, message);
assertEquals("bar",result);
assertEquals("bar", result);
result = this.resolver.resolveArgument(this.paramAnnotatedValue, message);
assertEquals("value",result);
assertEquals("value", result);
}
@Test(expected = MessageHandlingException.class)
@ -88,9 +87,6 @@ public class PathVariableMethodArgumentResolverTests { @@ -88,9 +87,6 @@ public class PathVariableMethodArgumentResolverTests {
}
@SuppressWarnings("unused")
private void handleMessage(
@PathVariable String foo,
@PathVariable(value = "name") String param1,
String param3) {
private void handleMessage(@PathVariable String foo, @PathVariable(value = "name") String param1, String param3) {
}
}

8
spring-messaging/src/test/java/org/springframework/messaging/simp/handler/SimpMessageTypeMessageConditionTests.java

@ -16,17 +16,13 @@ @@ -16,17 +16,13 @@
package org.springframework.messaging.simp.handler;
import org.junit.Test;
import org.springframework.messaging.Message;
import org.springframework.messaging.handler.condition.DestinationPatternsMessageCondition;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for SimpMessageTypeMessageCondition.
@ -35,7 +31,6 @@ import static org.junit.Assert.assertEquals; @@ -35,7 +31,6 @@ import static org.junit.Assert.assertEquals;
*/
public class SimpMessageTypeMessageConditionTests {
@Test
public void combineEmptySets() {
SimpMessageTypeMessageCondition c1 = condition();
@ -85,7 +80,6 @@ public class SimpMessageTypeMessageConditionTests { @@ -85,7 +80,6 @@ public class SimpMessageTypeMessageConditionTests {
assertEquals(0, condition(SimpMessageType.MESSAGE).compareTo(condition(SimpMessageType.MESSAGE), message));
}
private Message<byte[]> message(SimpMessageType messageType) {
MessageBuilder<byte[]> builder = MessageBuilder.withPayload(new byte[0]);
if (messageType != null) {

19
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java

@ -15,27 +15,26 @@ @@ -15,27 +15,26 @@
*/
package org.springframework.messaging.simp.stomp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import org.springframework.messaging.*;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
import org.springframework.messaging.simp.SimpMessageType;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.messaging.support.channel.ExecutorSubscribableChannel;
import org.springframework.messaging.support.tcp.ReconnectStrategy;
import org.springframework.messaging.support.tcp.TcpConnection;
import org.springframework.messaging.support.tcp.TcpConnectionHandler;
import org.springframework.messaging.support.tcp.TcpOperations;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureAdapter;
import org.springframework.util.concurrent.ListenableFutureTask;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
/**
* Unit tests for StompBrokerRelayMessageHandler.
@ -169,12 +168,14 @@ public class StompBrokerRelayMessageHandlerTests { @@ -169,12 +168,14 @@ public class StompBrokerRelayMessageHandlerTests {
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message) {
this.messages.add((Message<byte[]>) message);
return true;
}
@Override
@SuppressWarnings("unchecked")
public boolean send(Message<?> message, long timeout) {
this.messages.add((Message<byte[]>) message);
return true;

5
spring-messaging/src/test/java/org/springframework/messaging/support/channel/PublishSubscibeChannelTests.java

@ -34,7 +34,6 @@ import org.springframework.messaging.support.MessageBuilder; @@ -34,7 +34,6 @@ import org.springframework.messaging.support.MessageBuilder;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* Tests for {@link ExecutorSubscribableChannel}.
@ -46,7 +45,6 @@ public class PublishSubscibeChannelTests { @@ -46,7 +45,6 @@ public class PublishSubscibeChannelTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
private ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
@Mock
@ -118,7 +116,7 @@ public class PublishSubscibeChannelTests { @@ -118,7 +116,7 @@ public class PublishSubscibeChannelTests {
try {
this.channel.send(message);
}
catch(MessageDeliveryException actualException) {
catch (MessageDeliveryException actualException) {
assertThat((RuntimeException) actualException.getCause(), equalTo(ex));
}
verifyZeroInteractions(secondHandler);
@ -127,6 +125,7 @@ public class PublishSubscibeChannelTests { @@ -127,6 +125,7 @@ public class PublishSubscibeChannelTests {
@Test
public void concurrentModification() throws Exception {
this.channel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
channel.unsubscribe(handler);

Loading…
Cancel
Save