diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java b/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java index 02f6c9dfd9..eef3757278 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java @@ -16,6 +16,7 @@ package org.springframework.messaging.core; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.springframework.beans.factory.InitializingBean; @@ -34,9 +35,9 @@ import org.springframework.util.Assert; */ public class CachingDestinationResolverProxy implements DestinationResolver, InitializingBean { - private final ConcurrentHashMap resolvedDestinationCache = new ConcurrentHashMap(); + private final Map resolvedDestinationCache = new ConcurrentHashMap(); - private DestinationResolver targetDestinationResolver; + private DestinationResolver targetDestinationResolver; /** @@ -47,14 +48,14 @@ public class CachingDestinationResolverProxy implements DestinationResolver targetDestinationResolver) { - Assert.notNull(targetDestinationResolver, "Target DestinationResolver must not be null"); - this.targetDestinationResolver = targetDestinationResolver; - } + * @param targetDestinationResolver the target DestinationResolver to delegate to + */ + public CachingDestinationResolverProxy(DestinationResolver targetDestinationResolver) { + Assert.notNull(targetDestinationResolver, "Target DestinationResolver must not be null"); + this.targetDestinationResolver = targetDestinationResolver; + } /** @@ -73,22 +74,21 @@ public class CachingDestinationResolverProxy implements DestinationResolver destinationResolver = (DestinationResolver) mock(DestinationResolver.class); - CachingDestinationResolverProxy cachingDestinationResolver = new CachingDestinationResolverProxy(destinationResolver); + @Test + public void cachedDestination() { + @SuppressWarnings("unchecked") + DestinationResolver destinationResolver = (DestinationResolver) mock(DestinationResolver.class); + CachingDestinationResolverProxy cachingDestinationResolver = new CachingDestinationResolverProxy(destinationResolver); - when(destinationResolver.resolveDestination("abcd")).thenReturn("dcba"); + when(destinationResolver.resolveDestination("abcd")).thenReturn("dcba"); when(destinationResolver.resolveDestination("1234")).thenReturn("4321"); - assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd")); - assertEquals("4321", cachingDestinationResolver.resolveDestination("1234")); + assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd")); + assertEquals("4321", cachingDestinationResolver.resolveDestination("1234")); assertEquals("4321", cachingDestinationResolver.resolveDestination("1234")); assertEquals("dcba", cachingDestinationResolver.resolveDestination("abcd")); - verify(destinationResolver, times(1)).resolveDestination("abcd"); + verify(destinationResolver, times(1)).resolveDestination("abcd"); verify(destinationResolver, times(1)).resolveDestination("1234"); - } + } @Test(expected = IllegalArgumentException.class) public void noTargetSet() { @@ -52,9 +53,9 @@ public class CachingDestinationResolverTests { cachingDestinationResolver.afterPropertiesSet(); } - @Test(expected = IllegalArgumentException.class) - public void nullTargetThroughConstructor() { - new CachingDestinationResolverProxy(null); - } + @Test(expected = IllegalArgumentException.class) + public void nullTargetThroughConstructor() { + new CachingDestinationResolverProxy(null); + } }