This commit is contained in:
Stéphane Nicoll 2024-01-12 09:27:39 +01:00
parent b16f379788
commit 122d8b9e4e
42 changed files with 230 additions and 240 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 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.
@ -27,10 +27,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Shinobu Aoki
* @author Juergen Hoeller
*/
public class TextMessageTests {
class TextMessageTests {
@Test
public void toStringWithAscii() {
void toStringWithAscii() {
String expected = "foo,bar";
TextMessage actual = new TextMessage(expected);
assertThat(actual.getPayload()).isEqualTo(expected);
@ -38,7 +38,7 @@ public class TextMessageTests {
}
@Test
public void toStringWithMultibyteString() {
void toStringWithMultibyteString() {
String expected = "\u3042\u3044\u3046\u3048\u304a";
TextMessage actual = new TextMessage(expected);
assertThat(actual.getPayload()).isEqualTo(expected);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 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.
@ -111,14 +111,14 @@ public class UndertowTestServer implements WebSocketTestServer {
}
@Override
public void start() throws Exception {
public void start() {
this.server.start();
Undertow.ListenerInfo info = this.server.getListenerInfo().get(0);
this.port = ((InetSocketAddress) info.getAddress()).getPort();
}
@Override
public void stop() throws Exception {
public void stop() {
this.server.stop();
this.port = 0;
}
@ -143,7 +143,7 @@ public class UndertowTestServer implements WebSocketTestServer {
}
@Override
public InstanceHandle<Servlet> createInstance() throws InstantiationException {
public InstanceHandle<Servlet> createInstance() {
return new InstanceHandle<>() {
@Override
public Servlet getInstance() {
@ -166,7 +166,7 @@ public class UndertowTestServer implements WebSocketTestServer {
}
@Override
public InstanceHandle<Filter> createInstance() throws InstantiationException {
public InstanceHandle<Filter> createInstance() {
return new InstanceHandle<>() {
@Override
public Filter getInstance() {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -29,10 +29,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* Test fixture for {@link WebSocketExtension}
* @author Brian Clozel
*/
public class WebSocketExtensionTests {
class WebSocketExtensionTests {
@Test
public void parseHeaderSingle() {
void parseHeaderSingle() {
List<WebSocketExtension> extensions =
WebSocketExtension.parseExtensions("x-test-extension ; foo=bar ; bar=baz");
@ -46,7 +46,7 @@ public class WebSocketExtensionTests {
}
@Test
public void parseHeaderMultiple() {
void parseHeaderMultiple() {
List<WebSocketExtension> extensions =
WebSocketExtension.parseExtensions("x-foo-extension, x-bar-extension");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -101,7 +101,7 @@ class WebSocketHandshakeTests extends AbstractWebSocketIntegrationTests {
}
@Bean
public TestWebSocketHandler handler() {
TestWebSocketHandler handler() {
return new TestWebSocketHandler();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
*
* @author Phillip Webb
*/
public class ConvertingEncoderDecoderSupportTests {
class ConvertingEncoderDecoderSupportTests {
private static final String CONVERTED_TEXT = "_test";
@ -64,12 +64,12 @@ public class ConvertingEncoderDecoderSupportTests {
@BeforeEach
public void setup() {
void setup() {
setup(Config.class);
}
@AfterEach
public void teardown() {
void teardown() {
ContextLoaderTestUtils.setCurrentWebApplicationContext(null);
}
@ -82,12 +82,12 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void encodeToText() throws Exception {
void encodeToText() throws Exception {
assertThat(new MyTextEncoder().encode(myType)).isEqualTo(CONVERTED_TEXT);
}
@Test
public void encodeToTextCannotConvert() throws Exception {
void encodeToTextCannotConvert() {
setup(NoConvertersConfig.class);
assertThatExceptionOfType(EncodeException.class).isThrownBy(() ->
new MyTextEncoder().encode(myType))
@ -95,13 +95,13 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void encodeToBinary() throws Exception {
void encodeToBinary() throws Exception {
assertThat(new MyBinaryEncoder().encode(myType).array())
.isEqualTo(CONVERTED_BYTES.array());
}
@Test
public void encodeToBinaryCannotConvert() throws Exception {
void encodeToBinaryCannotConvert() {
setup(NoConvertersConfig.class);
assertThatExceptionOfType(EncodeException.class).isThrownBy(() ->
new MyBinaryEncoder().encode(myType))
@ -109,14 +109,14 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void decodeFromText() throws Exception {
void decodeFromText() throws Exception {
Decoder.Text<MyType> decoder = new MyTextDecoder();
assertThat(decoder.willDecode(CONVERTED_TEXT)).isTrue();
assertThat(decoder.decode(CONVERTED_TEXT)).isEqualTo(myType);
}
@Test
public void decodeFromTextCannotConvert() throws Exception {
void decodeFromTextCannotConvert() {
setup(NoConvertersConfig.class);
Decoder.Text<MyType> decoder = new MyTextDecoder();
assertThat(decoder.willDecode(CONVERTED_TEXT)).isFalse();
@ -126,14 +126,14 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void decodeFromBinary() throws Exception {
void decodeFromBinary() throws Exception {
Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
assertThat(decoder.willDecode(CONVERTED_BYTES)).isTrue();
assertThat(decoder.decode(CONVERTED_BYTES)).isEqualTo(myType);
}
@Test
public void decodeFromBinaryCannotConvert() throws Exception {
void decodeFromBinaryCannotConvert() {
setup(NoConvertersConfig.class);
Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
assertThat(decoder.willDecode(CONVERTED_BYTES)).isFalse();
@ -143,28 +143,28 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void encodeAndDecodeText() throws Exception {
void encodeAndDecodeText() throws Exception {
MyTextEncoderDecoder encoderDecoder = new MyTextEncoderDecoder();
String encoded = encoderDecoder.encode(myType);
assertThat(encoderDecoder.decode(encoded)).isEqualTo(myType);
}
@Test
public void encodeAndDecodeBytes() throws Exception {
void encodeAndDecodeBytes() throws Exception {
MyBinaryEncoderDecoder encoderDecoder = new MyBinaryEncoderDecoder();
ByteBuffer encoded = encoderDecoder.encode(myType);
assertThat(encoderDecoder.decode(encoded)).isEqualTo(myType);
}
@Test
public void autowiresIntoEncoder() throws Exception {
void autowiresIntoEncoder() {
WithAutowire withAutowire = new WithAutowire();
withAutowire.init(null);
assertThat(withAutowire.config).isEqualTo(applicationContext.getBean(Config.class));
}
@Test
public void cannotFindApplicationContext() throws Exception {
void cannotFindApplicationContext() {
ContextLoaderTestUtils.setCurrentWebApplicationContext(null);
WithAutowire encoder = new WithAutowire();
encoder.init(null);
@ -174,7 +174,7 @@ public class ConvertingEncoderDecoderSupportTests {
}
@Test
public void cannotFindConversionService() throws Exception {
void cannotFindConversionService() {
setup(NoConfig.class);
MyBinaryEncoder encoder = new MyBinaryEncoder();
encoder.init(null);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -16,7 +16,6 @@
package org.springframework.web.socket.config;
import java.io.IOException;
import java.io.InputStream;
import java.time.Duration;
import java.time.Instant;
@ -70,13 +69,13 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Brian Clozel
* @author Rossen Stoyanchev
*/
public class HandlersBeanDefinitionParserTests {
class HandlersBeanDefinitionParserTests {
private final GenericWebApplicationContext appContext = new GenericWebApplicationContext();
@Test
public void webSocketHandlers() {
void webSocketHandlers() {
loadBeanDefinitions("websocket-config-handlers.xml");
Map<String, HandlerMapping> handlersMap = this.appContext.getBeansOfType(HandlerMapping.class);
@ -118,7 +117,7 @@ public class HandlersBeanDefinitionParserTests {
}
@Test
public void webSocketHandlersAttributes() {
void webSocketHandlersAttributes() {
loadBeanDefinitions("websocket-config-handlers-attributes.xml");
HandlerMapping handlerMapping = this.appContext.getBean(HandlerMapping.class);
@ -153,7 +152,7 @@ public class HandlersBeanDefinitionParserTests {
}
@Test
public void sockJs() {
void sockJs() {
loadBeanDefinitions("websocket-config-handlers-sockjs.xml");
SimpleUrlHandlerMapping handlerMapping = this.appContext.getBean(SimpleUrlHandlerMapping.class);
@ -196,7 +195,7 @@ public class HandlersBeanDefinitionParserTests {
}
@Test
public void sockJsAttributes() {
void sockJsAttributes() {
loadBeanDefinitions("websocket-config-handlers-sockjs-attributes.xml");
SimpleUrlHandlerMapping handlerMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
@ -312,7 +311,7 @@ class BarTestInterceptor extends FooTestInterceptor {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings("rawtypes")
class TestTaskScheduler implements TaskScheduler {
@Override
@ -355,12 +354,12 @@ class TestMessageCodec implements SockJsMessageCodec {
}
@Override
public String[] decode(String content) throws IOException {
public String[] decode(String content) {
return new String[0];
}
@Override
public String[] decodeInputStream(InputStream content) throws IOException {
public String[] decodeInputStream(InputStream content) {
return new String[0];
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -101,13 +101,13 @@ import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
* @author Artem Bilan
* @author Rossen Stoyanchev
*/
public class MessageBrokerBeanDefinitionParserTests {
class MessageBrokerBeanDefinitionParserTests {
private final GenericWebApplicationContext appContext = new GenericWebApplicationContext();
@Test
public void simpleBroker() throws Exception {
void simpleBroker() throws Exception {
loadBeanDefinitions("websocket-config-broker-simple.xml");
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
@ -231,7 +231,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void stompBrokerRelay() {
void stompBrokerRelay() {
loadBeanDefinitions("websocket-config-broker-relay.xml");
HandlerMapping hm = this.appContext.getBean(HandlerMapping.class);
@ -319,7 +319,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void annotationMethodMessageHandler() {
void annotationMethodMessageHandler() {
loadBeanDefinitions("websocket-config-broker-simple.xml");
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler =
@ -355,7 +355,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void customChannels() {
void customChannels() {
loadBeanDefinitions("websocket-config-broker-customchannels.xml");
SimpAnnotationMethodMessageHandler annotationMethodMessageHandler =
@ -393,7 +393,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void customArgumentAndReturnValueTypes() {
void customArgumentAndReturnValueTypes() {
loadBeanDefinitions("websocket-config-broker-custom-argument-and-return-value-types.xml");
SimpAnnotationMethodMessageHandler handler = this.appContext.getBean(SimpAnnotationMethodMessageHandler.class);
@ -410,7 +410,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void messageConverters() {
void messageConverters() {
loadBeanDefinitions("websocket-config-broker-converters.xml");
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
@ -421,7 +421,7 @@ public class MessageBrokerBeanDefinitionParserTests {
}
@Test
public void messageConvertersDefaultsOff() {
void messageConvertersDefaultsOff() {
loadBeanDefinitions("websocket-config-broker-converters-defaults-off.xml");
CompositeMessageConverter compositeConverter = this.appContext.getBean(CompositeMessageConverter.class);
@ -478,7 +478,7 @@ class CustomArgumentResolver implements HandlerMethodArgumentResolver {
}
@Override
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
public Object resolveArgument(MethodParameter parameter, Message<?> message) {
return null;
}
}
@ -492,7 +492,7 @@ class CustomReturnValueHandler implements HandlerMethodReturnValueHandler {
}
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception {
public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) {
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -39,7 +39,7 @@ import static org.mockito.Mockito.mock;
*
* @author Rossen Stoyanchev
*/
public class WebMvcStompEndpointRegistryTests {
class WebMvcStompEndpointRegistryTests {
private WebMvcStompEndpointRegistry endpointRegistry;
@ -47,7 +47,7 @@ public class WebMvcStompEndpointRegistryTests {
@BeforeEach
public void setup() {
void setup() {
SubscribableChannel inChannel = mock();
SubscribableChannel outChannel = mock();
this.webSocketHandler = new SubProtocolWebSocketHandler(inChannel, outChannel);
@ -59,7 +59,7 @@ public class WebMvcStompEndpointRegistryTests {
@Test
public void stompProtocolHandler() {
void stompProtocolHandler() {
this.endpointRegistry.addEndpoint("/stomp");
Map<String, SubProtocolHandler> protocolHandlers = webSocketHandler.getProtocolHandlerMap();
@ -70,7 +70,7 @@ public class WebMvcStompEndpointRegistryTests {
}
@Test
public void handlerMapping() {
void handlerMapping() {
SimpleUrlHandlerMapping hm = (SimpleUrlHandlerMapping) this.endpointRegistry.getHandlerMapping();
assertThat(hm.getUrlMap()).isEmpty();
@ -90,7 +90,7 @@ public class WebMvcStompEndpointRegistryTests {
}
@Test
public void errorHandler() throws Exception {
void errorHandler() {
StompSubProtocolErrorHandler errorHandler = mock();
this.endpointRegistry.setErrorHandler(errorHandler);
this.endpointRegistry.addEndpoint("/stompOverWebSocket");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -185,8 +185,8 @@ class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(requestHandler.getHandshakeInterceptors()).hasSize(2);
assertThat(requestHandler.getHandshakeInterceptors()).element(0).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1)).isInstanceOf(OriginHandshakeInterceptor.class);
}
@Test
@ -209,8 +209,8 @@ class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
assertThat(requestHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(requestHandler.getHandshakeInterceptors()).hasSize(2);
assertThat(requestHandler.getHandshakeInterceptors()).element(0).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
assertThat(requestHandler.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(requestHandler.getHandshakeInterceptors().get(1)).isInstanceOf(OriginHandshakeInterceptor.class);
}
@Test
@ -239,8 +239,8 @@ class WebMvcStompWebSocketEndpointRegistrationTests {
WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(sockJsService.getHandshakeInterceptors()).hasSize(2);
assertThat(sockJsService.getHandshakeInterceptors()).element(0).isEqualTo(interceptor);
assertThat(sockJsService.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
assertThat(sockJsService.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(sockJsService.getHandshakeInterceptors().get(1)).isInstanceOf(OriginHandshakeInterceptor.class);
}
@Test
@ -271,8 +271,8 @@ class WebMvcStompWebSocketEndpointRegistrationTests {
WebSocketTransportHandler transportHandler = (WebSocketTransportHandler) handlers.get(TransportType.WEBSOCKET);
assertThat(transportHandler.getHandshakeHandler()).isSameAs(handshakeHandler);
assertThat(sockJsService.getHandshakeInterceptors()).hasSize(2);
assertThat(sockJsService.getHandshakeInterceptors()).element(0).isEqualTo(interceptor);
assertThat(sockJsService.getHandshakeInterceptors().get(1).getClass()).isEqualTo(OriginHandshakeInterceptor.class);
assertThat(sockJsService.getHandshakeInterceptors().get(0)).isEqualTo(interceptor);
assertThat(sockJsService.getHandshakeInterceptors().get(1)).isInstanceOf(OriginHandshakeInterceptor.class);
assertThat(sockJsService.getAllowedOrigins()).contains(origin);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -95,7 +95,7 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
}
@Bean
public TestHandler serverHandler() {
TestHandler serverHandler() {
return new TestHandler();
}
}
@ -103,10 +103,10 @@ class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTests {
private static class TestHandler extends AbstractWebSocketHandler {
private CountDownLatch connectLatch = new CountDownLatch(1);
private final CountDownLatch connectLatch = new CountDownLatch(1);
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
public void afterConnectionEstablished(WebSocketSession session) {
this.connectLatch.countDown();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
*
* @author Rossen Stoyanchev
*/
public class WebSocketHandlerRegistrationTests {
class WebSocketHandlerRegistrationTests {
private TestWebSocketHandlerRegistration registration = new TestWebSocketHandlerRegistration();
@ -50,7 +50,7 @@ public class WebSocketHandlerRegistrationTests {
@Test
public void minimal() {
void minimal() {
WebSocketHandler handler = new TextWebSocketHandler();
this.registration.addHandler(handler, "/foo", "/bar");
@ -73,7 +73,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void interceptors() {
void interceptors() {
WebSocketHandler handler = new TextWebSocketHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
@ -92,7 +92,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void emptyAllowedOrigin() {
void emptyAllowedOrigin() {
WebSocketHandler handler = new TextWebSocketHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
@ -111,7 +111,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void interceptorsWithAllowedOrigins() {
void interceptorsWithAllowedOrigins() {
WebSocketHandler handler = new TextWebSocketHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
@ -136,7 +136,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void interceptorsPassedToSockJsRegistration() {
void interceptorsPassedToSockJsRegistration() {
WebSocketHandler handler = new TextWebSocketHandler();
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
@ -157,7 +157,7 @@ public class WebSocketHandlerRegistrationTests {
assertThat(mapping.sockJsService).isNotNull();
assertThat(mapping.sockJsService.getAllowedOrigins()).contains("https://mydomain1.example");
List<HandshakeInterceptor> interceptors = mapping.sockJsService.getHandshakeInterceptors();
assertThat(interceptors).element(0).isEqualTo(interceptor);
assertThat(interceptors.get(0)).isEqualTo(interceptor);
OriginHandshakeInterceptor originInterceptor = (OriginHandshakeInterceptor) interceptors.get(1);
assertThat(originInterceptor.getAllowedOrigins()).containsExactly("https://mydomain1.example");
@ -165,7 +165,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void handshakeHandler() {
void handshakeHandler() {
WebSocketHandler handler = new TextWebSocketHandler();
HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
@ -181,7 +181,7 @@ public class WebSocketHandlerRegistrationTests {
}
@Test
public void handshakeHandlerPassedToSockJsRegistration() {
void handshakeHandlerPassedToSockJsRegistration() {
WebSocketHandler handler = new TextWebSocketHandler();
HandshakeHandler handshakeHandler = new DefaultHandshakeHandler();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -33,11 +33,11 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Rossen Stoyanchev
*/
public class BeanCreatingHandlerProviderTests {
class BeanCreatingHandlerProviderTests {
@Test
public void getHandlerSimpleInstantiation() {
void getHandlerSimpleInstantiation() {
BeanCreatingHandlerProvider<SimpleEchoHandler> provider =
new BeanCreatingHandlerProvider<>(SimpleEchoHandler.class);
@ -46,9 +46,8 @@ public class BeanCreatingHandlerProviderTests {
}
@Test
public void getHandlerWithBeanFactory() {
void getHandlerWithBeanFactory() {
@SuppressWarnings("resource")
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
BeanCreatingHandlerProvider<EchoHandler> provider =
@ -59,7 +58,7 @@ public class BeanCreatingHandlerProviderTests {
}
@Test
public void getHandlerNoBeanFactory() {
void getHandlerNoBeanFactory() {
BeanCreatingHandlerProvider<EchoHandler> provider =
new BeanCreatingHandlerProvider<>(EchoHandler.class);
@ -73,7 +72,7 @@ public class BeanCreatingHandlerProviderTests {
static class Config {
@Bean
public EchoService echoService() {
EchoService echoService() {
return new EchoService();
}
}

View File

@ -36,11 +36,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("resource")
public class ConcurrentWebSocketSessionDecoratorTests {
class ConcurrentWebSocketSessionDecoratorTests {
@Test
public void send() throws IOException {
void send() throws IOException {
TestWebSocketSession session = new TestWebSocketSession();
session.setOpen(true);
@ -51,8 +50,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
TextMessage textMessage = new TextMessage("payload");
decorator.sendMessage(textMessage);
assertThat(session.getSentMessages()).hasSize(1);
assertThat(session.getSentMessages()).element(0).isEqualTo(textMessage);
assertThat(session.getSentMessages()).containsExactly(textMessage);
assertThat(decorator.getBufferSize()).isEqualTo(0);
assertThat(decorator.getTimeSinceSendStarted()).isEqualTo(0);
@ -60,7 +58,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
}
@Test
public void sendAfterBlockedSend() throws IOException, InterruptedException {
void sendAfterBlockedSend() throws IOException, InterruptedException {
BlockingWebSocketSession session = new BlockingWebSocketSession();
session.setOpen(true);
@ -84,7 +82,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
}
@Test
public void sendTimeLimitExceeded() throws InterruptedException {
void sendTimeLimitExceeded() throws InterruptedException {
BlockingWebSocketSession session = new BlockingWebSocketSession();
session.setId("123");
@ -95,7 +93,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
sendBlockingMessage(decorator);
// Exceed send time..
// Exceed send time
Thread.sleep(200);
TextMessage payload = new TextMessage("payload");
@ -106,7 +104,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
}
@Test
public void sendBufferSizeExceeded() throws IOException, InterruptedException {
void sendBufferSizeExceeded() throws IOException, InterruptedException {
BlockingWebSocketSession session = new BlockingWebSocketSession();
session.setId("123");
@ -154,7 +152,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
}
@Test
public void closeStatusNormal() throws Exception {
void closeStatusNormal() throws Exception {
BlockingWebSocketSession session = new BlockingWebSocketSession();
session.setOpen(true);
@ -168,7 +166,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
}
@Test
public void closeStatusChangesToSessionNotReliable() throws Exception {
void closeStatusChangesToSessionNotReliable() throws Exception {
BlockingWebSocketSession session = new BlockingWebSocketSession();
session.setId("123");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 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.
@ -30,13 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class PerConnectionWebSocketHandlerTests {
class PerConnectionWebSocketHandlerTests {
@Test
public void afterConnectionEstablished() throws Exception {
void afterConnectionEstablished() throws Exception {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.refresh();
@ -69,7 +68,7 @@ public class PerConnectionWebSocketHandlerTests {
}
@Override
public void destroy() throws Exception {
public void destroy() {
destroyCount++;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 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.
@ -25,10 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class WebSocketHandlerDecoratorTests {
class WebSocketHandlerDecoratorTests {
@Test
public void getLastHandler() {
void getLastHandler() {
AbstractWebSocketHandler h1 = new AbstractWebSocketHandler() {
};
WebSocketHandlerDecorator h2 = new WebSocketHandlerDecorator(h1);

View File

@ -33,17 +33,17 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class WebSocketHttpHeadersTests {
class WebSocketHttpHeadersTests {
private WebSocketHttpHeaders headers;
@BeforeEach
public void setUp() {
void setUp() {
headers = new WebSocketHttpHeaders();
}
@Test
public void parseWebSocketExtensions() {
void parseWebSocketExtensions() {
List<String> extensions = new ArrayList<>();
extensions.add("x-foo-extension, x-bar-extension");
extensions.add("x-test-extension");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -41,10 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev
* @since 4.0
*/
public class DefaultSimpUserRegistryTests {
class DefaultSimpUserRegistryTests {
@Test
public void addOneSessionId() {
void addOneSessionId() {
TestPrincipal user = new TestPrincipal("joe");
Message<byte[]> message = createMessage(SimpMessageType.CONNECT_ACK, "123");
SessionConnectedEvent event = new SessionConnectedEvent(this, message, user);
@ -61,7 +61,7 @@ public class DefaultSimpUserRegistryTests {
}
@Test
public void addMultipleSessionIds() {
void addMultipleSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
@ -88,7 +88,7 @@ public class DefaultSimpUserRegistryTests {
}
@Test
public void removeSessionIds() {
void removeSessionIds() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
@ -122,7 +122,7 @@ public class DefaultSimpUserRegistryTests {
}
@Test
public void findSubscriptions() throws Exception {
void findSubscriptions() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");
@ -154,7 +154,7 @@ public class DefaultSimpUserRegistryTests {
}
@Test
public void nullSessionId() throws Exception {
void nullSessionId() {
DefaultSimpUserRegistry registry = new DefaultSimpUserRegistry();
TestPrincipal user = new TestPrincipal("joe");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -70,7 +70,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class OrderedMessageSendingIntegrationTests {
class OrderedMessageSendingIntegrationTests {
private static final Log logger = LogFactory.getLog(OrderedMessageSendingIntegrationTests.class);
@ -88,7 +88,7 @@ public class OrderedMessageSendingIntegrationTests {
@BeforeEach
public void setup() {
void setup() {
this.blockingSession = new BlockingWebSocketSession();
this.blockingSession.setId("1");
this.blockingSession.setOpen(true);
@ -105,7 +105,7 @@ public class OrderedMessageSendingIntegrationTests {
}
@AfterEach
public void tearDown() {
void tearDown() {
this.executor.shutdown();
}
@ -157,7 +157,7 @@ public class OrderedMessageSendingIntegrationTests {
// Send one to block
this.orderedClientOutChannel.send(createMessage(0));
// Exceed send time..
// Exceed send time
Thread.sleep(200);
CountDownLatch messageLatch = new CountDownLatch(1);

View File

@ -33,19 +33,19 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class StompSubProtocolErrorHandlerTests {
class StompSubProtocolErrorHandlerTests {
private StompSubProtocolErrorHandler handler;
@BeforeEach
public void setUp() throws Exception {
void setUp() {
this.handler = new StompSubProtocolErrorHandler();
}
@Test
public void handleClientMessageProcessingError() throws Exception {
void handleClientMessageProcessingError() {
Exception ex = new Exception("fake exception");
Message<byte[]> actual = this.handler.handleClientMessageProcessingError(null, ex);
@ -59,7 +59,7 @@ public class StompSubProtocolErrorHandlerTests {
}
@Test
public void handleClientMessageProcessingErrorWithReceipt() throws Exception {
void handleClientMessageProcessingErrorWithReceipt() {
String receiptId = "123";
StompHeaderAccessor clientHeaderAccessor = StompHeaderAccessor.create(StompCommand.SEND);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -68,7 +68,7 @@ public class SubProtocolWebSocketHandlerTests {
@BeforeEach
public void setup() {
void setup() {
this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
given(mqttHandler.getSupportedProtocols()).willReturn(List.of("MQTT"));
@ -79,7 +79,7 @@ public class SubProtocolWebSocketHandlerTests {
@Test
public void subProtocolMatch() throws Exception {
void subProtocolMatch() throws Exception {
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler));
this.session.setAcceptedProtocol("v12.sToMp");
this.webSocketHandler.afterConnectionEstablished(session);
@ -90,7 +90,7 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void subProtocolDefaultHandlerOnly() throws Exception {
void subProtocolDefaultHandlerOnly() throws Exception {
this.webSocketHandler.setDefaultProtocolHandler(stompHandler);
this.session.setAcceptedProtocol("v12.sToMp");
this.webSocketHandler.afterConnectionEstablished(session);
@ -100,7 +100,7 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void subProtocolNoMatch() throws Exception {
void subProtocolNoMatch() {
this.webSocketHandler.setDefaultProtocolHandler(defaultHandler);
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler));
this.session.setAcceptedProtocol("wamp");
@ -110,7 +110,7 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void nullSubProtocol() throws Exception {
void nullSubProtocol() throws Exception {
this.webSocketHandler.setDefaultProtocolHandler(defaultHandler);
this.webSocketHandler.afterConnectionEstablished(session);
@ -121,7 +121,7 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void emptySubProtocol() throws Exception {
void emptySubProtocol() throws Exception {
this.session.setAcceptedProtocol("");
this.webSocketHandler.setDefaultProtocolHandler(this.defaultHandler);
this.webSocketHandler.afterConnectionEstablished(session);
@ -133,7 +133,7 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void noSubProtocolOneHandler() throws Exception {
void noSubProtocolOneHandler() throws Exception {
this.webSocketHandler.setProtocolHandlers(List.of(stompHandler));
this.webSocketHandler.afterConnectionEstablished(session);
@ -142,14 +142,14 @@ public class SubProtocolWebSocketHandlerTests {
}
@Test
public void noSubProtocolTwoHandlers() throws Exception {
void noSubProtocolTwoHandlers() {
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler));
assertThatIllegalStateException().isThrownBy(() ->
this.webSocketHandler.afterConnectionEstablished(session));
}
@Test
public void noSubProtocolNoDefaultHandler() throws Exception {
void noSubProtocolNoDefaultHandler() {
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler, mqttHandler));
assertThatIllegalStateException().isThrownBy(() ->
this.webSocketHandler.afterConnectionEstablished(session));

View File

@ -42,7 +42,7 @@ import static org.mockito.Mockito.mock;
*
* @author Rossen Stoyanchev
*/
public class WebSocketAnnotationMethodMessageHandlerTests {
class WebSocketAnnotationMethodMessageHandlerTests {
private TestWebSocketAnnotationMethodMessageHandler messageHandler;
@ -50,7 +50,7 @@ public class WebSocketAnnotationMethodMessageHandlerTests {
@BeforeEach
public void setUp() throws Exception {
void setUp() {
this.applicationContext = new StaticApplicationContext();
this.applicationContext.registerSingleton("controller", TestController.class);
this.applicationContext.registerSingleton("controllerAdvice", TestControllerAdvice.class);
@ -65,7 +65,7 @@ public class WebSocketAnnotationMethodMessageHandlerTests {
}
@Test
public void globalException() throws Exception {
void globalException() {
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create();
headers.setSessionId("session1");
headers.setSessionAttributes(new ConcurrentHashMap<>());

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@ -86,7 +86,7 @@ class WebSocketStompClientIntegrationTests {
}
@AfterEach
void tearDown() throws Exception {
void tearDown() {
try {
this.server.undeployConfig();
}

View File

@ -86,7 +86,7 @@ class WebSocketStompClientTests {
@BeforeEach
void setUp() throws Exception {
void setUp() {
WebSocketClient webSocketClient = mock();
this.stompClient = new TestWebSocketStompClient(webSocketClient);
this.stompClient.setTaskScheduler(this.taskScheduler);
@ -100,7 +100,7 @@ class WebSocketStompClientTests {
@Test
void webSocketHandshakeFailure() throws Exception {
void webSocketHandshakeFailure() {
connect();
IllegalStateException handshakeFailure = new IllegalStateException("simulated exception");
@ -229,7 +229,7 @@ class WebSocketStompClientTests {
}
@Test
void heartbeatDefaultValue() throws Exception {
void heartbeatDefaultValue() {
WebSocketStompClient stompClient = new WebSocketStompClient(mock());
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {0, 0});
@ -238,7 +238,7 @@ class WebSocketStompClientTests {
}
@Test
void heartbeatDefaultValueWithScheduler() throws Exception {
void heartbeatDefaultValueWithScheduler() {
WebSocketStompClient stompClient = new WebSocketStompClient(mock());
stompClient.setTaskScheduler(mock());
assertThat(stompClient.getDefaultHeartbeat()).isEqualTo(new long[] {10000, 10000});
@ -248,7 +248,7 @@ class WebSocketStompClientTests {
}
@Test
void heartbeatDefaultValueSetWithoutScheduler() throws Exception {
void heartbeatDefaultValueSetWithoutScheduler() {
WebSocketStompClient stompClient = new WebSocketStompClient(mock());
stompClient.setDefaultHeartbeat(new long[] {5, 5});
assertThatIllegalStateException().isThrownBy(() ->

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -41,7 +41,7 @@ import static org.mockito.Mockito.verify;
*
* @author Rossen Stoyanchev
*/
public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
private RequestUpgradeStrategy upgradeStrategy = mock();
@ -49,7 +49,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
@Test
public void supportedSubProtocols() {
void supportedSubProtocols() {
this.handshakeHandler.setSupportedProtocols("stomp", "mqtt");
given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
@ -65,7 +65,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
}
@Test
public void supportedExtensions() {
void supportedExtensions() {
WebSocketExtension extension1 = new WebSocketExtension("ext1");
WebSocketExtension extension2 = new WebSocketExtension("ext2");
@ -84,7 +84,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
}
@Test
public void subProtocolCapableHandler() {
void subProtocolCapableHandler() {
given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
this.servletRequest.setMethod("GET");
@ -99,7 +99,7 @@ public class DefaultHandshakeHandlerTests extends AbstractHttpRequestTests {
}
@Test
public void subProtocolCapableHandlerNoMatch() {
void subProtocolCapableHandlerNoMatch() {
given(this.upgradeStrategy.getSupportedVersions()).willReturn(new String[] {"13"});
this.servletRequest.setMethod("GET");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -34,13 +34,12 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Rossen Stoyanchev
*/
public class ServerEndpointRegistrationTests {
class ServerEndpointRegistrationTests {
@Test
public void endpointPerConnection() throws Exception {
void endpointPerConnection() throws Exception {
@SuppressWarnings("resource")
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", EchoEndpoint.class);
@ -52,7 +51,7 @@ public class ServerEndpointRegistrationTests {
}
@Test
public void endpointSingleton() throws Exception {
void endpointSingleton() throws Exception {
EchoEndpoint endpoint = new EchoEndpoint(new EchoService());
ServerEndpointRegistration registration = new ServerEndpointRegistration("/path", endpoint);
@ -67,7 +66,7 @@ public class ServerEndpointRegistrationTests {
static class Config {
@Bean
public EchoService echoService() {
EchoService echoService() {
return new EchoService();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -44,7 +44,7 @@ public class SpringConfiguratorTests {
@BeforeEach
public void setup() {
void setup() {
this.servletContext = new MockServletContext();
this.webAppContext = new AnnotationConfigWebApplicationContext();
@ -57,26 +57,26 @@ public class SpringConfiguratorTests {
}
@AfterEach
public void destroy() {
void destroy() {
this.contextLoader.closeWebApplicationContext(this.servletContext);
}
@Test
public void getEndpointPerConnection() throws Exception {
void getEndpointPerConnection() throws Exception {
PerConnectionEchoEndpoint endpoint = this.configurator.getEndpointInstance(PerConnectionEchoEndpoint.class);
assertThat(endpoint).isNotNull();
}
@Test
public void getEndpointSingletonByType() throws Exception {
void getEndpointSingletonByType() throws Exception {
EchoEndpoint expected = this.webAppContext.getBean(EchoEndpoint.class);
EchoEndpoint actual = this.configurator.getEndpointInstance(EchoEndpoint.class);
assertThat(actual).isSameAs(expected);
}
@Test
public void getEndpointSingletonByComponentName() throws Exception {
void getEndpointSingletonByComponentName() throws Exception {
ComponentEchoEndpoint expected = this.webAppContext.getBean(ComponentEchoEndpoint.class);
ComponentEchoEndpoint actual = this.configurator.getEndpointInstance(ComponentEchoEndpoint.class);
assertThat(actual).isSameAs(expected);
@ -88,12 +88,12 @@ public class SpringConfiguratorTests {
static class Config {
@Bean
public EchoEndpoint javaConfigEndpoint() {
EchoEndpoint javaConfigEndpoint() {
return new EchoEndpoint(echoService());
}
@Bean
public EchoService echoService() {
EchoService echoService() {
return new EchoService();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -35,14 +35,14 @@ import static org.mockito.Mockito.mock;
*
* @author Rossen Stoyanchev
*/
public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTests {
class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTests {
private final Map<String, Object> attributes = new HashMap<>();
private final WebSocketHandler wsHandler = mock();
@Test
public void defaultConstructor() throws Exception {
void defaultConstructor() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
@ -57,7 +57,7 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
}
@Test
public void constructorWithAttributeNames() throws Exception {
void constructorWithAttributeNames() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
this.servletRequest.getSession().setAttribute("bar", "baz");
@ -72,7 +72,7 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
}
@Test
public void doNotCopyHttpSessionId() throws Exception {
void doNotCopyHttpSessionId() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
@ -86,7 +86,7 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
@Test
public void doNotCopyAttributes() throws Exception {
void doNotCopyAttributes() throws Exception {
this.servletRequest.setSession(new MockHttpSession(null, "123"));
this.servletRequest.getSession().setAttribute("foo", "bar");
@ -99,7 +99,7 @@ public class HttpSessionHandshakeInterceptorTests extends AbstractHttpRequestTes
}
@Test
public void doNotCauseSessionCreation() throws Exception {
void doNotCauseSessionCreation() throws Exception {
HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
interceptor.beforeHandshake(this.request, this.response, wsHandler, attributes);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -40,19 +40,19 @@ import static org.mockito.Mockito.mock;
*
* @author Sebastien Deleuze
*/
public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
private final Map<String, Object> attributes = new HashMap<>();
private final WebSocketHandler wsHandler = mock();
@Test
public void invalidInput() {
void invalidInput() {
assertThatIllegalArgumentException().isThrownBy(() -> new OriginHandshakeInterceptor(null));
}
@Test
public void originValueMatch() throws Exception {
void originValueMatch() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.example");
List<String> allowed = Collections.singletonList("https://mydomain1.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
@ -61,7 +61,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void originValueNoMatch() throws Exception {
void originValueNoMatch() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.example");
List<String> allowed = Collections.singletonList("https://mydomain2.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
@ -70,7 +70,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void originListMatch() throws Exception {
void originListMatch() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.example");
List<String> allowed = Arrays.asList("https://mydomain1.example", "https://mydomain2.example", "http://mydomain3.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
@ -79,7 +79,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void originListNoMatch() throws Exception {
void originListNoMatch() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.example/");
List<String> allowed = Arrays.asList("https://mydomain1.example", "https://mydomain2.example", "http://mydomain3.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(allowed);
@ -88,7 +88,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void originNoMatchWithNullHostileCollection() throws Exception {
void originNoMatchWithNullHostileCollection() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://www.mydomain4.example/");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
@ -99,7 +99,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void originMatchAll() throws Exception {
void originMatchAll() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
interceptor.setAllowedOrigins(Collections.singletonList("*"));
@ -108,7 +108,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.example");
this.servletRequest.setServerName("mydomain2.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());
@ -117,7 +117,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void sameOriginMatchWithAllowedOrigins() throws Exception {
void sameOriginMatchWithAllowedOrigins() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.example");
this.servletRequest.setServerName("mydomain2.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(List.of("http://mydomain1.example"));
@ -126,7 +126,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
}
@Test
public void sameOriginNoMatch() throws Exception {
void sameOriginNoMatch() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain3.example");
this.servletRequest.setServerName("mydomain2.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Collections.emptyList());

View File

@ -16,7 +16,6 @@
package org.springframework.web.socket.sockjs.client;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.List;
@ -79,7 +78,7 @@ class ClientSockJsSessionTests {
}
@Test
void handleFrameOpenWhenStatusNotNew() throws Exception {
void handleFrameOpenWhenStatusNotNew() {
this.session.handleFrame(SockJsFrame.openFrame().getContent());
assertThat(this.session.isOpen()).isTrue();
this.session.handleFrame(SockJsFrame.openFrame().getContent());
@ -183,7 +182,7 @@ class ClientSockJsSessionTests {
}
@Test
void closeWithNullStatus() throws Exception {
void closeWithNullStatus() {
this.session.handleFrame(SockJsFrame.openFrame().getContent());
assertThatIllegalArgumentException()
.isThrownBy(() -> this.session.close(null))
@ -191,7 +190,7 @@ class ClientSockJsSessionTests {
}
@Test
void closeWithStatusOutOfRange() throws Exception {
void closeWithStatusOutOfRange() {
this.session.handleFrame(SockJsFrame.openFrame().getContent());
assertThatIllegalArgumentException()
.isThrownBy(() -> this.session.close(new CloseStatus(2999, "reason")))
@ -225,12 +224,12 @@ class ClientSockJsSessionTests {
}
@Override
protected void sendInternal(TextMessage textMessage) throws IOException {
protected void sendInternal(TextMessage textMessage) {
this.sentMessage = textMessage;
}
@Override
protected void disconnect(CloseStatus status) throws IOException {
protected void disconnect(CloseStatus status) {
this.disconnectStatus = status;
}

View File

@ -51,7 +51,6 @@ class DefaultTransportRequestTests {
private CompletableFuture<WebSocketSession> connectFuture = new CompletableFuture<>();
@SuppressWarnings("unchecked")
private BiConsumer<WebSocketSession, Throwable> connectCallback = mock();
private TestTransport webSocketTransport = new TestTransport("WebSocketTestTransport");

View File

@ -133,7 +133,7 @@ class RestTemplateXhrTransportTests {
void connectFailure() {
final HttpServerErrorException expected = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR);
RestOperations restTemplate = mock();
given(restTemplate.execute((URI) any(), eq(HttpMethod.POST), any(), any())).willThrow(expected);
given(restTemplate.execute(any(), eq(HttpMethod.POST), any(), any())).willThrow(expected);
final CountDownLatch latch = new CountDownLatch(1);
connect(restTemplate).addCallback(

View File

@ -17,7 +17,6 @@
package org.springframework.web.socket.sockjs.client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
@ -58,7 +57,7 @@ class SockJsClientTests {
private final XhrTestTransport xhrTransport = new XhrTestTransport("XhrTestTransport");
@SuppressWarnings({ "deprecation", "unchecked" })
@SuppressWarnings("deprecation")
private org.springframework.util.concurrent.ListenableFutureCallback<WebSocketSession> connectCallback = mock();
private SockJsClient sockJsClient = new SockJsClient(List.of(this.webSocketTransport, this.xhrTransport));
@ -83,7 +82,7 @@ class SockJsClientTests {
@Test
@SuppressWarnings("deprecation")
void connectWebSocketDisabled() throws URISyntaxException {
void connectWebSocketDisabled() {
setupInfoRequest(false);
this.sockJsClient.doHandshake(handler, URL);
assertThat(this.webSocketTransport.invoked()).isFalse();
@ -162,7 +161,7 @@ class SockJsClientTests {
@Test
@SuppressWarnings("deprecation")
void connectInfoRequestFailure() throws URISyntaxException {
void connectInfoRequestFailure() {
HttpServerErrorException exception = new HttpServerErrorException(HttpStatus.SERVICE_UNAVAILABLE);
given(this.infoReceiver.executeInfoRequest(any(), any())).willThrow(exception);
this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -75,7 +75,6 @@ class TestTransport implements Transport {
return captor.getValue();
}
@SuppressWarnings("unchecked")
@Override
public CompletableFuture<WebSocketSession> connectAsync(TransportRequest request, WebSocketHandler handler) {
this.request = request;

View File

@ -26,11 +26,11 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rossen Stoyanchev
* @since 4.1
*/
public class SockJsFrameTests {
class SockJsFrameTests {
@Test
public void openFrame() {
void openFrame() {
SockJsFrame frame = SockJsFrame.openFrame();
assertThat(frame.getContent()).isEqualTo("o");
@ -39,7 +39,7 @@ public class SockJsFrameTests {
}
@Test
public void heartbeatFrame() {
void heartbeatFrame() {
SockJsFrame frame = SockJsFrame.heartbeatFrame();
assertThat(frame.getContent()).isEqualTo("h");
@ -48,7 +48,7 @@ public class SockJsFrameTests {
}
@Test
public void messageArrayFrame() {
void messageArrayFrame() {
SockJsFrame frame = SockJsFrame.messageFrame(new Jackson2SockJsMessageCodec(), "m1", "m2");
assertThat(frame.getContent()).isEqualTo("a[\"m1\",\"m2\"]");
@ -57,7 +57,7 @@ public class SockJsFrameTests {
}
@Test
public void messageArrayFrameEmpty() {
void messageArrayFrameEmpty() {
SockJsFrame frame = new SockJsFrame("a");
assertThat(frame.getContent()).isEqualTo("a[]");
@ -72,7 +72,7 @@ public class SockJsFrameTests {
}
@Test
public void closeFrame() {
void closeFrame() {
SockJsFrame frame = SockJsFrame.closeFrame(3000, "Go Away!");
assertThat(frame.getContent()).isEqualTo("c[3000,\"Go Away!\"]");
@ -81,7 +81,7 @@ public class SockJsFrameTests {
}
@Test
public void closeFrameEmpty() {
void closeFrameEmpty() {
SockJsFrame frame = new SockJsFrame("c");
assertThat(frame.getContent()).isEqualTo("c[]");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -281,7 +281,7 @@ class SockJsServiceTests extends AbstractHttpRequestTests {
@Override
protected void handleRawWebSocketRequest(ServerHttpRequest req, ServerHttpResponse res,
WebSocketHandler handler) throws IOException {
WebSocketHandler handler) {
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2024 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.
@ -23,10 +23,10 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rossen Stoyanchev
*/
public class TransportTypeTests {
class TransportTypeTests {
@Test
public void testFromValue() {
void testFromValue() {
assertThat(TransportType.fromValue("websocket")).isEqualTo(TransportType.WEBSOCKET);
assertThat(TransportType.fromValue("xhr")).isEqualTo(TransportType.XHR);
assertThat(TransportType.fromValue("xhr_send")).isEqualTo(TransportType.XHR_SEND);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -91,7 +91,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
@Override
@BeforeEach
public void setup() {
protected void setup() {
super.setup();
Map<String, Object> attributes = Collections.emptyMap();
@ -147,7 +147,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestXhr() throws Exception {
void handleTransportRequestXhr() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@ -162,7 +162,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test // SPR-12226
void handleTransportRequestXhrAllowedOriginsMatch() throws Exception {
void handleTransportRequestXhrAllowedOriginsMatch() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example", "https://mydomain2.example"));
@ -173,7 +173,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test // SPR-12226
void handleTransportRequestXhrAllowedOriginsNoMatch() throws Exception {
void handleTransportRequestXhrAllowedOriginsNoMatch() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example", "https://mydomain2.example"));
@ -184,7 +184,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test // SPR-13464
void handleTransportRequestXhrSameOrigin() throws Exception {
void handleTransportRequestXhrSameOrigin() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
@ -196,7 +196,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test // SPR-13545
void handleInvalidTransportType() throws Exception {
void handleInvalidTransportType() {
String sockJsPath = sessionUrlPrefix + "invalid";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
@ -208,7 +208,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestXhrOptions() throws Exception {
void handleTransportRequestXhrOptions() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("OPTIONS", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@ -220,7 +220,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestNoSuitableHandler() throws Exception {
void handleTransportRequestNoSuitableHandler() {
String sockJsPath = sessionUrlPrefix + "eventsource";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@ -229,7 +229,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestXhrSend() throws Exception {
void handleTransportRequestXhrSend() {
String sockJsPath = sessionUrlPrefix + "xhr_send";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@ -258,7 +258,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestXhrSendWithDifferentUser() throws Exception {
void handleTransportRequestXhrSendWithDifferentUser() {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@ -281,7 +281,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestWebsocket() throws Exception {
void handleTransportRequestWebsocket() {
TransportHandlingSockJsService wsService = new TransportHandlingSockJsService(
this.taskScheduler, this.wsTransportHandler);
String sockJsPath = "/websocket";
@ -306,7 +306,7 @@ class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
}
@Test
void handleTransportRequestIframe() throws Exception {
void handleTransportRequestIframe() {
String sockJsPath = "/iframe.html";
setRequest("GET", sockJsPrefix + sockJsPath);
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -52,7 +52,7 @@ class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests {
}
@Test
void readMessagesBadContent() throws Exception {
void readMessagesBadContent() {
this.servletRequest.setContent("".getBytes(UTF_8));
handleRequestAndExpectFailure();
@ -61,7 +61,7 @@ class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests {
}
@Test
void readMessagesNoSession() throws Exception {
void readMessagesNoSession() {
WebSocketHandler webSocketHandler = mock();
assertThatIllegalArgumentException().isThrownBy(() ->
new XhrReceivingTransportHandler().handleRequest(this.request, this.response, webSocketHandler, null));
@ -93,11 +93,11 @@ class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests {
transportHandler.initialize(new StubSockJsServiceConfig());
transportHandler.handleRequest(this.request, this.response, wsHandler, session);
assertThat(this.response.getHeaders().getContentType().toString()).isEqualTo("text/plain;charset=UTF-8");
assertThat(this.response.getHeaders().getContentType()).hasToString("text/plain;charset=UTF-8");
verify(wsHandler).handleMessage(session, new TextMessage("x"));
}
private void handleRequestAndExpectFailure() throws Exception {
private void handleRequestAndExpectFailure() {
resetResponse();
WebSocketHandler wsHandler = mock();

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@ -135,7 +135,7 @@ class HttpSendingTransportHandlerTests extends AbstractHttpRequestTests {
}
@Test
void frameFormats() throws Exception {
void frameFormats() {
this.servletRequest.setQueryString("c=callback");
this.servletRequest.addParameter("c", "callback");

View File

@ -36,10 +36,10 @@ import static org.mockito.Mockito.mock;
*
* @author Rossen Stoyanchev
*/
public class SockJsWebSocketHandlerTests {
class SockJsWebSocketHandlerTests {
@Test
public void getSubProtocols() throws Exception {
void getSubProtocols() {
SubscribableChannel channel = mock();
SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
@ -54,7 +54,7 @@ public class SockJsWebSocketHandlerTests {
}
@Test
public void getSubProtocolsNone() throws Exception {
void getSubProtocolsNone() {
WebSocketHandler handler = new TextWebSocketHandler();
TaskScheduler scheduler = mock();
DefaultSockJsService service = new DefaultSockJsService(scheduler);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2024 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.
@ -209,7 +209,7 @@ public class TestSockJsSession extends AbstractSockJsSession {
}
@Override
protected void disconnect(CloseStatus status) throws IOException {
protected void disconnect(CloseStatus status) {
this.closeStatus = status;
}

View File

@ -64,7 +64,7 @@ class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTests<TestW
@Test
void isActive() throws Exception {
void isActive() {
assertThat(this.session.isActive()).isFalse();
this.session.initializeDelegateSession(this.webSocketSession);
@ -85,7 +85,7 @@ class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTests<TestW
@Test
@SuppressWarnings("resource")
void afterSessionInitializedOpenFrameFirst() throws Exception {
void afterSessionInitializedOpenFrameFirst() {
TextWebSocketHandler handler = new TextWebSocketHandler() {
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
@ -123,7 +123,7 @@ class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTests<TestW
}
@Test
void sendMessageInternal() throws Exception {
void sendMessageInternal() {
this.session.initializeDelegateSession(this.webSocketSession);
this.session.sendMessageInternal("x");