diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/TextMessageTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/TextMessageTests.java index c2009464d26..1254f55f90f 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/TextMessageTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/TextMessageTests.java @@ -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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java b/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java index 50f618eb8e8..e26ce172bd2 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/UndertowTestServer.java @@ -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 createInstance() throws InstantiationException { + public InstanceHandle createInstance() { return new InstanceHandle<>() { @Override public Servlet getInstance() { @@ -166,7 +166,7 @@ public class UndertowTestServer implements WebSocketTestServer { } @Override - public InstanceHandle createInstance() throws InstantiationException { + public InstanceHandle createInstance() { return new InstanceHandle<>() { @Override public Filter getInstance() { diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java index 168c0a52193..2ab23568efb 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketExtensionTests.java @@ -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 extensions = WebSocketExtension.parseExtensions("x-test-extension ; foo=bar ; bar=baz"); @@ -46,7 +46,7 @@ public class WebSocketExtensionTests { } @Test - public void parseHeaderMultiple() { + void parseHeaderMultiple() { List extensions = WebSocketExtension.parseExtensions("x-foo-extension, x-bar-extension"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java index e380bcfb20e..74990097e18 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/WebSocketHandshakeTests.java @@ -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(); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupportTests.java index 8cc8a6fa48a..04fa8def071 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/adapter/standard/ConvertingEncoderDecoderSupportTests.java @@ -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 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 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 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 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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/HandlersBeanDefinitionParserTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/HandlersBeanDefinitionParserTests.java index 978d32f77e8..759893a5dd4 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/HandlersBeanDefinitionParserTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/HandlersBeanDefinitionParserTests.java @@ -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 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]; } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java index 59e431dd957..529f553c0de 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java @@ -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) { } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java index 88793372b39..09579c98e6f 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompEndpointRegistryTests.java @@ -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 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"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistrationTests.java index faa2f53eba3..569595014a0 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistrationTests.java @@ -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); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java index 951f6e213ca..d9fd68e2d30 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationTests.java @@ -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(); } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketHandlerRegistrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketHandlerRegistrationTests.java index 171b8f90db8..1b96b355cf1 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketHandlerRegistrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketHandlerRegistrationTests.java @@ -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 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(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/handler/BeanCreatingHandlerProviderTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/handler/BeanCreatingHandlerProviderTests.java index 27f79bfb3f1..65a098c6f5c 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/handler/BeanCreatingHandlerProviderTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/handler/BeanCreatingHandlerProviderTests.java @@ -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 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 provider = @@ -59,7 +58,7 @@ public class BeanCreatingHandlerProviderTests { } @Test - public void getHandlerNoBeanFactory() { + void getHandlerNoBeanFactory() { BeanCreatingHandlerProvider provider = new BeanCreatingHandlerProvider<>(EchoHandler.class); @@ -73,7 +72,7 @@ public class BeanCreatingHandlerProviderTests { static class Config { @Bean - public EchoService echoService() { + EchoService echoService() { return new EchoService(); } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java index 00b49020b44..15074872743 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecoratorTests.java @@ -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"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/handler/PerConnectionWebSocketHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/handler/PerConnectionWebSocketHandlerTests.java index 72c4357fa1b..b513edbf8be 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/handler/PerConnectionWebSocketHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/handler/PerConnectionWebSocketHandlerTests.java @@ -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++; } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHandlerDecoratorTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHandlerDecoratorTests.java index 5f19bc11d5f..bbe25e55e0d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHandlerDecoratorTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHandlerDecoratorTests.java @@ -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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHttpHeadersTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHttpHeadersTests.java index c44dbc2225a..cf4d7ff571e 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHttpHeadersTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/handler/WebSocketHttpHeadersTests.java @@ -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 extensions = new ArrayList<>(); extensions.add("x-foo-extension, x-bar-extension"); extensions.add("x-test-extension"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistryTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistryTests.java index decca24a417..8b22ba1adec 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistryTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/DefaultSimpUserRegistryTests.java @@ -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 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"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/OrderedMessageSendingIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/OrderedMessageSendingIntegrationTests.java index 735619cff20..a405fc0351f 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/OrderedMessageSendingIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/OrderedMessageSendingIntegrationTests.java @@ -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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolErrorHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolErrorHandlerTests.java index 8e9e4ac4bbe..052aed5670b 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolErrorHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/StompSubProtocolErrorHandlerTests.java @@ -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 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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java index 0abf386f51f..c1ef8b828d3 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java @@ -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)); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandlerTests.java index 9494b831d30..1c819836241 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketAnnotationMethodMessageHandlerTests.java @@ -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<>()); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientIntegrationTests.java index c4203bc96ca..f8b7b538661 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientIntegrationTests.java @@ -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(); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java index 8753ecf15db..019bed80396 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/messaging/WebSocketStompClientTests.java @@ -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(() -> diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/DefaultHandshakeHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/DefaultHandshakeHandlerTests.java index 6ea57d7905c..4a8cdc08227 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/DefaultHandshakeHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/DefaultHandshakeHandlerTests.java @@ -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"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/ServerEndpointRegistrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/ServerEndpointRegistrationTests.java index 7e32bc93adc..4553f54cc4d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/ServerEndpointRegistrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/ServerEndpointRegistrationTests.java @@ -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(); } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/SpringConfiguratorTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/SpringConfiguratorTests.java index 156d3ec48fb..54978a409b4 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/SpringConfiguratorTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/standard/SpringConfiguratorTests.java @@ -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(); } } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptorTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptorTests.java index a2f0f8d2514..33cc315fc4f 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptorTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/support/HttpSessionHandshakeInterceptorTests.java @@ -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 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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptorTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptorTests.java index 6577c7bf5cb..e956eb925a8 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptorTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptorTests.java @@ -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 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 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 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 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 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 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()); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/ClientSockJsSessionTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/ClientSockJsSessionTests.java index ad304205d81..80ca072fc93 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/ClientSockJsSessionTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/ClientSockJsSessionTests.java @@ -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; } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequestTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequestTests.java index 04d000f6d5c..b7c792dfab0 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequestTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/DefaultTransportRequestTests.java @@ -51,7 +51,6 @@ class DefaultTransportRequestTests { private CompletableFuture connectFuture = new CompletableFuture<>(); - @SuppressWarnings("unchecked") private BiConsumer connectCallback = mock(); private TestTransport webSocketTransport = new TestTransport("WebSocketTestTransport"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java index dea8cc1fe57..e32b78c6f2d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/RestTemplateXhrTransportTests.java @@ -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( diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java index f2df211478d..10da16a5fc8 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsClientTests.java @@ -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 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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/TestTransport.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/TestTransport.java index d153b1fa97c..594ea05bcac 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/TestTransport.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/TestTransport.java @@ -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 connectAsync(TransportRequest request, WebSocketHandler handler) { this.request = request; diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/frame/SockJsFrameTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/frame/SockJsFrameTests.java index 7be85a16c97..80b490152d2 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/frame/SockJsFrameTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/frame/SockJsFrameTests.java @@ -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[]"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java index 83d1070da7a..a63db42bcd6 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/support/SockJsServiceTests.java @@ -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 diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/TransportTypeTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/TransportTypeTests.java index a3f651ff67b..f01d7e841ad 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/TransportTypeTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/TransportTypeTests.java @@ -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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/DefaultSockJsServiceTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/DefaultSockJsServiceTests.java index 816fe1bc667..b3ae02493a5 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/DefaultSockJsServiceTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/DefaultSockJsServiceTests.java @@ -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 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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpReceivingTransportHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpReceivingTransportHandlerTests.java index 1ee8d36e5bb..a85f672e5e8 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpReceivingTransportHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpReceivingTransportHandlerTests.java @@ -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(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java index cf10cf0b7cf..46fcdba687c 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/HttpSendingTransportHandlerTests.java @@ -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"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/SockJsWebSocketHandlerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/SockJsWebSocketHandlerTests.java index 7e9cf2ba524..eb471a38431 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/SockJsWebSocketHandlerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/SockJsWebSocketHandlerTests.java @@ -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); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/TestSockJsSession.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/TestSockJsSession.java index 53d659d1f38..1e856f420f2 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/TestSockJsSession.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/TestSockJsSession.java @@ -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; } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSessionTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSessionTests.java index 8f08b82f54b..79733172cb4 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSessionTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSessionTests.java @@ -64,7 +64,7 @@ class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTests