diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java index ffe9a711504..badd6afc70b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java @@ -154,7 +154,7 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler } Encoder encoder = getEncoder(elementType, mimeType); - return Flux.from((Publisher) publisher).map(value -> + return Flux.from(publisher).map(value -> encodeValue(value, elementType, encoder, bufferFactory, mimeType, hints)); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java index b0de4fde096..a92fc40d129 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java @@ -566,14 +566,6 @@ public abstract class AbstractMethodMessageHandler this.handlerMethod = handlerMethod; } - public T getMapping() { - return this.mapping; - } - - public HandlerMethod getHandlerMethod() { - return this.handlerMethod; - } - @Override public String toString() { return this.mapping.toString(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java index 153d940bcb9..3ff2745f5f0 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/DefaultSubscriptionRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -541,6 +541,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { } @Override + @SuppressWarnings("rawtypes") public TypedValue read(EvaluationContext context, @Nullable Object target, String name) { Object value; if (target instanceof Message) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java index d33e8548b0f..cd91ab3b54d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java @@ -215,6 +215,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati } } + @SuppressWarnings("unused") public void setId(String id) { this.id = id; } @@ -223,6 +224,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati return this.id; } + @SuppressWarnings("unused") public void setUserMap(Map users) { this.users = users; } @@ -297,6 +299,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati } } + @SuppressWarnings("unused") public void setName(String name) { this.name = name; } @@ -328,6 +331,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati return null; } + @SuppressWarnings("unused") public void setSessions(Set sessions) { this.sessions.addAll(sessions); } @@ -407,6 +411,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati } } + @SuppressWarnings("unused") public void setId(String id) { this.id = id; } @@ -425,6 +430,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati return this.user; } + @SuppressWarnings("unused") public void setSubscriptions(Set subscriptions) { this.subscriptions.addAll(subscriptions); } @@ -487,6 +493,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati this.destination = subscription.getDestination(); } + @SuppressWarnings("unused") public void setId(String id) { this.id = id; } @@ -505,6 +512,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati return this.session; } + @SuppressWarnings("unused") public void setDestination(String destination) { this.destination = destination; } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolverTests.java index 45d89dc8a3a..c5cff938c8f 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolverTests.java @@ -51,6 +51,7 @@ public class HeaderMethodArgumentResolverTests { @BeforeEach + @SuppressWarnings("resource") public void setup() { GenericApplicationContext context = new GenericApplicationContext(); context.refresh(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java index 503ef454ed8..8db7f97f17d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/support/HeaderMethodArgumentResolverTests.java @@ -53,6 +53,7 @@ public class HeaderMethodArgumentResolverTests { @BeforeEach + @SuppressWarnings("resource") public void setup() { GenericApplicationContext context = new GenericApplicationContext(); context.refresh(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java index 8b2a879e8b2..c5b5b9ecf0b 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -64,7 +64,6 @@ public class StubArgumentResolver implements HandlerMethodArgumentResolver { return parameter.getParameterType().equals(this.valueType); } - @SuppressWarnings("unchecked") @Override public Mono resolveArgument(MethodParameter parameter, Message message) { this.resolvedParameters.add(parameter); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java index 86b496da7f9..22ea181370f 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.messaging.handler.invocation.reactive; import org.reactivestreams.Publisher; @@ -44,7 +45,7 @@ public class TestReturnValueHandler implements HandlerMethodReturnValueHandler { } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public Mono handleReturnValue(@Nullable Object value, MethodParameter returnType, Message message) { return value instanceof Publisher ? new ChannelSendOperator((Publisher) value, this::saveValue) : diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandlerTests.java index 26b24fbe8e8..92eefda1fbb 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandlerTests.java @@ -237,6 +237,7 @@ public class SubscriptionMethodReturnValueHandlerTests { private String withoutView; + @SuppressWarnings("unused") public String getWithView1() { return withView1; } @@ -245,6 +246,7 @@ public class SubscriptionMethodReturnValueHandlerTests { this.withView1 = withView1; } + @SuppressWarnings("unused") public String getWithView2() { return withView2; } @@ -253,6 +255,7 @@ public class SubscriptionMethodReturnValueHandlerTests { this.withView2 = withView2; } + @SuppressWarnings("unused") public String getWithoutView() { return withoutView; } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandlerTests.java index cae2ac4e387..456bd9f1d21 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandlerTests.java @@ -180,8 +180,8 @@ public class SimpleBrokerMessageHandlerTests { this.messageHandler::start); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings("rawtypes") public void startAndStopWithHeartbeatValue() { ScheduledFuture future = mock(ScheduledFuture.class); given(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), eq(15000L))).willReturn(future); @@ -199,7 +199,6 @@ public class SimpleBrokerMessageHandlerTests { verifyNoMoreInteractions(future); } - @SuppressWarnings("unchecked") @Test public void startWithOneZeroHeartbeatValue() { this.messageHandler.setTaskScheduler(this.taskScheduler); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java index 3bf8372f841..4b67d290fb5 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.messaging.simp.stomp; import java.util.ArrayList; @@ -46,11 +47,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Unit tests for StompBrokerRelayMessageHandler. + * Unit tests for {@link StompBrokerRelayMessageHandler}. * * @author Rossen Stoyanchev */ -public class StompBrokerRelayMessageHandlerTests { +class StompBrokerRelayMessageHandlerTests { private StompBrokerRelayMessageHandler brokerRelay; @@ -60,7 +61,7 @@ public class StompBrokerRelayMessageHandlerTests { @BeforeEach - public void setup() { + void setup() { this.outboundChannel = new StubMessageChannel(); @@ -80,7 +81,7 @@ public class StompBrokerRelayMessageHandlerTests { @Test - public void virtualHost() throws Exception { + void virtualHost() { this.brokerRelay.setVirtualHost("ABC"); @@ -101,7 +102,7 @@ public class StompBrokerRelayMessageHandlerTests { } @Test - public void loginAndPasscode() throws Exception { + void loginAndPasscode() { this.brokerRelay.setSystemLogin("syslogin"); this.brokerRelay.setSystemPasscode("syspasscode"); @@ -125,7 +126,7 @@ public class StompBrokerRelayMessageHandlerTests { } @Test - public void destinationExcluded() throws Exception { + void destinationExcluded() { this.brokerRelay.start(); @@ -141,7 +142,7 @@ public class StompBrokerRelayMessageHandlerTests { } @Test - public void messageFromBrokerIsEnriched() throws Exception { + void messageFromBrokerIsEnriched() { this.brokerRelay.start(); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); @@ -161,7 +162,7 @@ public class StompBrokerRelayMessageHandlerTests { // SPR-12820 @Test - public void connectWhenBrokerNotAvailable() throws Exception { + void connectWhenBrokerNotAvailable() { this.brokerRelay.start(); this.brokerRelay.stopInternal(); @@ -176,7 +177,7 @@ public class StompBrokerRelayMessageHandlerTests { } @Test - public void sendAfterBrokerUnavailable() throws Exception { + void sendAfterBrokerUnavailable() { this.brokerRelay.start(); assertThat(this.brokerRelay.getConnectionCount()).isEqualTo(1); @@ -197,7 +198,8 @@ public class StompBrokerRelayMessageHandlerTests { } @Test - public void systemSubscription() throws Exception { + @SuppressWarnings("rawtypes") + void systemSubscription() { MessageHandler handler = mock(MessageHandler.class); this.brokerRelay.setSystemSubscriptions(Collections.singletonMap("/topic/foo", handler)); @@ -247,18 +249,7 @@ public class StompBrokerRelayMessageHandlerTests { private static ListenableFutureTask getVoidFuture() { ListenableFutureTask futureTask = new ListenableFutureTask<>(new Callable() { @Override - public Void call() throws Exception { - return null; - } - }); - futureTask.run(); - return futureTask; - } - - private static ListenableFutureTask getBooleanFuture() { - ListenableFutureTask futureTask = new ListenableFutureTask<>(new Callable() { - @Override - public Boolean call() throws Exception { + public Void call() { return null; } }); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/MultiServerUserRegistryTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/MultiServerUserRegistryTests.java index 9bbc42b7a0f..553c3af380c 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/MultiServerUserRegistryTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/MultiServerUserRegistryTests.java @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -39,25 +38,17 @@ import static org.mockito.Mockito.mock; * * @author Rossen Stoyanchev */ -public class MultiServerUserRegistryTests { +class MultiServerUserRegistryTests { - private SimpUserRegistry localRegistry; + private final SimpUserRegistry localRegistry = Mockito.mock(SimpUserRegistry.class); - private MultiServerUserRegistry registry; + private final MultiServerUserRegistry registry = new MultiServerUserRegistry(this.localRegistry); - private MessageConverter converter; - - - @BeforeEach - public void setup() throws Exception { - this.localRegistry = Mockito.mock(SimpUserRegistry.class); - this.registry = new MultiServerUserRegistry(this.localRegistry); - this.converter = new MappingJackson2MessageConverter(); - } + private final MessageConverter converter = new MappingJackson2MessageConverter(); @Test - public void getUserFromLocalRegistry() throws Exception { + void getUserFromLocalRegistry() { SimpUser user = Mockito.mock(SimpUser.class); Set users = Collections.singleton(user); given(this.localRegistry.getUsers()).willReturn(users); @@ -69,7 +60,7 @@ public class MultiServerUserRegistryTests { } @Test - public void getUserFromRemoteRegistry() throws Exception { + void getUserFromRemoteRegistry() { // Prepare broadcast message from remote server TestSimpUser testUser = new TestSimpUser("joe"); TestSimpSession testSession = new TestSimpSession("remote-sess"); @@ -100,7 +91,7 @@ public class MultiServerUserRegistryTests { } @Test - public void findSubscriptionsFromRemoteRegistry() throws Exception { + void findSubscriptionsFromRemoteRegistry() { // Prepare broadcast message from remote server TestSimpUser user1 = new TestSimpUser("joe"); TestSimpUser user2 = new TestSimpUser("jane"); @@ -133,7 +124,7 @@ public class MultiServerUserRegistryTests { } @Test // SPR-13800 - public void getSessionsWhenUserIsConnectedToMultipleServers() throws Exception { + void getSessionsWhenUserIsConnectedToMultipleServers() { // Add user to local registry TestSimpUser localUser = new TestSimpUser("joe"); TestSimpSession localSession = new TestSimpSession("sess123"); @@ -169,7 +160,7 @@ public class MultiServerUserRegistryTests { } @Test - public void purgeExpiredRegistries() throws Exception { + void purgeExpiredRegistries() { // Prepare broadcast message from remote server TestSimpUser testUser = new TestSimpUser("joe"); testUser.addSessions(new TestSimpSession("remote-sub")); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java index 7cae1cc285e..78c8dd3a5f3 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java @@ -18,7 +18,6 @@ package org.springframework.messaging.simp.user; import java.nio.charset.StandardCharsets; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -41,31 +40,22 @@ import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.springframework.messaging.simp.SimpMessageHeaderAccessor.ORIGINAL_DESTINATION; /** - * Unit tests for - * {@link org.springframework.messaging.simp.user.UserDestinationMessageHandler}. + * Unit tests for {@link UserDestinationMessageHandler}. */ -public class UserDestinationMessageHandlerTests { +class UserDestinationMessageHandlerTests { private static final String SESSION_ID = "123"; - private UserDestinationMessageHandler handler; + private final SimpUserRegistry registry = mock(SimpUserRegistry.class); - private SimpUserRegistry registry; + private final SubscribableChannel brokerChannel = mock(SubscribableChannel.class); - private SubscribableChannel brokerChannel; - - - @BeforeEach - public void setup() { - this.registry = mock(SimpUserRegistry.class); - this.brokerChannel = mock(SubscribableChannel.class); - UserDestinationResolver resolver = new DefaultUserDestinationResolver(this.registry); - this.handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, resolver); - } + private final UserDestinationMessageHandler handler = new UserDestinationMessageHandler(new StubMessageChannel(), this.brokerChannel, new DefaultUserDestinationResolver(this.registry)); @Test - public void handleSubscribe() { + @SuppressWarnings("rawtypes") + void handleSubscribe() { given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); this.handler.handleMessage(createWith(SimpMessageType.SUBSCRIBE, "joe", SESSION_ID, "/user/queue/foo")); @@ -77,7 +67,8 @@ public class UserDestinationMessageHandlerTests { } @Test - public void handleUnsubscribe() { + @SuppressWarnings("rawtypes") + void handleUnsubscribe() { given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); this.handler.handleMessage(createWith(SimpMessageType.UNSUBSCRIBE, "joe", "123", "/user/queue/foo")); @@ -89,7 +80,8 @@ public class UserDestinationMessageHandlerTests { } @Test - public void handleMessage() { + @SuppressWarnings("rawtypes") + void handleMessage() { TestSimpUser simpUser = new TestSimpUser("joe"); simpUser.addSessions(new TestSimpSession("123")); given(this.registry.getUser("joe")).willReturn(simpUser); @@ -105,7 +97,8 @@ public class UserDestinationMessageHandlerTests { } @Test - public void handleMessageWithoutActiveSession() { + @SuppressWarnings("rawtypes") + void handleMessageWithoutActiveSession() { this.handler.setBroadcastDestination("/topic/unresolved"); given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo")); @@ -125,7 +118,8 @@ public class UserDestinationMessageHandlerTests { } @Test - public void handleMessageFromBrokerWithActiveSession() { + @SuppressWarnings("rawtypes") + void handleMessageFromBrokerWithActiveSession() { TestSimpUser simpUser = new TestSimpUser("joe"); simpUser.addSessions(new TestSimpSession("123")); given(this.registry.getUser("joe")).willReturn(simpUser); @@ -153,7 +147,7 @@ public class UserDestinationMessageHandlerTests { } @Test - public void handleMessageFromBrokerWithoutActiveSession() { + void handleMessageFromBrokerWithoutActiveSession() { this.handler.setBroadcastDestination("/topic/unresolved"); given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true); @@ -170,7 +164,7 @@ public class UserDestinationMessageHandlerTests { } @Test - public void ignoreMessage() { + void ignoreMessage() { // no destination this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", null)); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserRegistryMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserRegistryMessageHandlerTests.java index 98f2caea15b..e01348ff64d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserRegistryMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserRegistryMessageHandlerTests.java @@ -89,8 +89,8 @@ public class UserRegistryMessageHandlerTests { assertThat(runnable).isNotNull(); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings({ "unchecked", "rawtypes" }) public void brokerUnavailableEvent() throws Exception { ScheduledFuture future = mock(ScheduledFuture.class); @@ -106,6 +106,7 @@ public class UserRegistryMessageHandlerTests { } @Test + @SuppressWarnings("rawtypes") public void broadcastRegistry() throws Exception { given(this.brokerChannel.send(any())).willReturn(true);