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 c5754ad326fa..8727b4372011 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 @@ -59,7 +59,7 @@ void subProtocolNegotiation(WebSocketTestServer server, WebSocketClient webSocke WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); headers.setSecWebSocketProtocol("foo"); - URI url = new URI(getWsBaseUrl() + "/ws"); + URI url = URI.create(getWsBaseUrl() + "/ws"); WebSocketSession session = this.webSocketClient.doHandshake(new TextWebSocketHandler(), headers, url).get(); assertThat(session.getAcceptedProtocol()).isEqualTo("foo"); session.close(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java index 0e03ca55cb23..d6fbc45ea45d 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java @@ -39,11 +39,10 @@ * * @author Rossen Stoyanchev */ -public class WebSocketConnectionManagerTests { - +class WebSocketConnectionManagerTests { @Test - public void openConnection() throws Exception { + void openConnection() { List subprotocols = List.of("abc"); TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false); @@ -57,7 +56,7 @@ public void openConnection() throws Exception { expectedHeaders.setSecWebSocketProtocol(subprotocols); assertThat(client.headers).isEqualTo(expectedHeaders); - assertThat(client.uri).isEqualTo(new URI("/path/123")); + assertThat(client.uri).isEqualTo(URI.create("/path/123")); WebSocketHandlerDecorator loggingHandler = (WebSocketHandlerDecorator) client.webSocketHandler; assertThat(loggingHandler.getClass()).isEqualTo(LoggingWebSocketHandlerDecorator.class); @@ -66,7 +65,7 @@ public void openConnection() throws Exception { } @Test - public void clientLifecycle() throws Exception { + void clientLifecycle() throws Exception { TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false); WebSocketHandler handler = new TextWebSocketHandler(); WebSocketConnectionManager manager = new WebSocketConnectionManager(client, handler , "/a"); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java index 338063ad6b7f..94a682e86ab5 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/client/standard/StandardWebSocketClientTests.java @@ -25,7 +25,6 @@ import jakarta.websocket.ClientEndpointConfig; import jakarta.websocket.Endpoint; import jakarta.websocket.WebSocketContainer; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -46,31 +45,21 @@ * * @author Rossen Stoyanchev */ -public class StandardWebSocketClientTests { +class StandardWebSocketClientTests { - private StandardWebSocketClient wsClient; + private final WebSocketHandler wsHandler = new AbstractWebSocketHandler() {}; - private WebSocketContainer wsContainer; + private final WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); - private WebSocketHandler wsHandler; + private final WebSocketContainer wsContainer = mock(WebSocketContainer.class); - private WebSocketHttpHeaders headers; - - - @BeforeEach - public void setup() { - this.headers = new WebSocketHttpHeaders(); - this.wsHandler = new AbstractWebSocketHandler() { - }; - this.wsContainer = mock(WebSocketContainer.class); - this.wsClient = new StandardWebSocketClient(this.wsContainer); - } + private final StandardWebSocketClient wsClient = new StandardWebSocketClient(this.wsContainer); @Test @SuppressWarnings("deprecation") - public void testGetLocalAddress() throws Exception { - URI uri = new URI("ws://localhost/abc"); + void getLocalAddress() throws Exception { + URI uri = URI.create("ws://localhost/abc"); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertThat(session.getLocalAddress()).isNotNull(); @@ -79,8 +68,8 @@ public void testGetLocalAddress() throws Exception { @Test @SuppressWarnings("deprecation") - public void testGetLocalAddressWss() throws Exception { - URI uri = new URI("wss://localhost/abc"); + void getLocalAddressWss() throws Exception { + URI uri = URI.create("wss://localhost/abc"); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertThat(session.getLocalAddress()).isNotNull(); @@ -89,16 +78,16 @@ public void testGetLocalAddressWss() throws Exception { @Test @SuppressWarnings("deprecation") - public void testGetLocalAddressNoScheme() throws Exception { - URI uri = new URI("localhost/abc"); + void getLocalAddressNoScheme() { + URI uri = URI.create("localhost/abc"); assertThatIllegalArgumentException().isThrownBy(() -> this.wsClient.doHandshake(this.wsHandler, this.headers, uri)); } @Test @SuppressWarnings("deprecation") - public void testGetRemoteAddress() throws Exception { - URI uri = new URI("wss://localhost/abc"); + void getRemoteAddress() throws Exception { + URI uri = URI.create("wss://localhost/abc"); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertThat(session.getRemoteAddress()).isNotNull(); @@ -108,8 +97,8 @@ public void testGetRemoteAddress() throws Exception { @Test @SuppressWarnings("deprecation") - public void handshakeHeaders() throws Exception { - URI uri = new URI("ws://localhost/abc"); + void handshakeHeaders() throws Exception { + URI uri = URI.create("ws://localhost/abc"); List protocols = Collections.singletonList("abc"); this.headers.setSecWebSocketProtocol(protocols); this.headers.add("foo", "bar"); @@ -122,8 +111,8 @@ public void handshakeHeaders() throws Exception { @Test @SuppressWarnings("deprecation") - public void clientEndpointConfig() throws Exception { - URI uri = new URI("ws://localhost/abc"); + void clientEndpointConfig() throws Exception { + URI uri = URI.create("ws://localhost/abc"); List protocols = Collections.singletonList("abc"); this.headers.setSecWebSocketProtocol(protocols); @@ -138,10 +127,10 @@ public void clientEndpointConfig() throws Exception { @Test @SuppressWarnings("deprecation") - public void clientEndpointConfigWithUserProperties() throws Exception { + void clientEndpointConfigWithUserProperties() throws Exception { Map userProperties = Collections.singletonMap("foo", "bar"); - URI uri = new URI("ws://localhost/abc"); + URI uri = URI.create("ws://localhost/abc"); this.wsClient.setUserProperties(userProperties); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); @@ -154,8 +143,8 @@ public void clientEndpointConfigWithUserProperties() throws Exception { @Test @SuppressWarnings("deprecation") - public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception { - URI uri = new URI("ws://localhost/abc"); + void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws Exception { + URI uri = URI.create("ws://localhost/abc"); this.headers.add("foo", "bar"); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); @@ -171,8 +160,8 @@ public void standardWebSocketClientConfiguratorInsertsHandshakeHeaders() throws @Test @SuppressWarnings("deprecation") - public void taskExecutor() throws Exception { - URI uri = new URI("ws://localhost/abc"); + void taskExecutor() throws Exception { + URI uri = URI.create("ws://localhost/abc"); this.wsClient.setTaskExecutor(new SimpleAsyncTaskExecutor()); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java index 72bac1536834..71f002643d32 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/AbstractSockJsIntegrationTests.java @@ -266,7 +266,7 @@ private void testEcho(int messageCount, Transport transport, WebSocketHttpHeader } TestClientHandler handler = new TestClientHandler(); initSockJsClient(transport); - URI url = new URI(this.baseUrl + "/echo"); + URI url = URI.create(this.baseUrl + "/echo"); WebSocketSession session = this.sockJsClient.doHandshake(handler, headers, url).get(); for (TextMessage message : messages) { session.sendMessage(message); @@ -285,7 +285,7 @@ private void testReceiveOneMessage(Transport transport, WebSocketHttpHeaders hea TestClientHandler clientHandler = new TestClientHandler(); initSockJsClient(transport); - this.sockJsClient.doHandshake(clientHandler, headers, new URI(this.baseUrl + "/test")).get(); + this.sockJsClient.doHandshake(clientHandler, headers, URI.create(this.baseUrl + "/test")).get(); TestServerHandler serverHandler = this.wac.getBean(TestServerHandler.class); assertThat(clientHandler.session).as("afterConnectionEstablished should have been called").isNotNull(); 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 2c22903c8c46..db91f067d4f7 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 @@ -48,7 +48,7 @@ * * @author Rossen Stoyanchev */ -public class ClientSockJsSessionTests { +class ClientSockJsSessionTests { private static final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec(); @@ -60,8 +60,8 @@ public class ClientSockJsSessionTests { @BeforeEach - public void setup() throws Exception { - SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com")); + void setup() { + SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com")); Transport transport = mock(Transport.class); TransportRequest request = new DefaultTransportRequest(urlInfo, null, null, transport, TransportType.XHR, CODEC); this.handler = mock(WebSocketHandler.class); @@ -71,7 +71,7 @@ public void setup() throws Exception { @Test - public void handleFrameOpen() throws Exception { + void handleFrameOpen() throws Exception { assertThat(this.session.isOpen()).isFalse(); this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThat(this.session.isOpen()).isTrue(); @@ -82,7 +82,7 @@ public void handleFrameOpen() throws Exception { } @Test - public void handleFrameOpenWhenStatusNotNew() throws Exception { + void handleFrameOpenWhenStatusNotNew() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThat(this.session.isOpen()).isTrue(); this.session.handleFrame(SockJsFrame.openFrame().getContent()); @@ -90,14 +90,14 @@ public void handleFrameOpenWhenStatusNotNew() throws Exception { } @Test - public void handleFrameOpenWithWebSocketHandlerException() throws Exception { + void handleFrameOpenWithWebSocketHandlerException() throws Exception { willThrow(new IllegalStateException("Fake error")).given(this.handler).afterConnectionEstablished(this.session); this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThat(this.session.isOpen()).isTrue(); } @Test - public void handleFrameMessage() throws Exception { + void handleFrameMessage() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.handleFrame(SockJsFrame.messageFrame(CODEC, "foo", "bar").getContent()); verify(this.handler).afterConnectionEstablished(this.session); @@ -107,7 +107,7 @@ public void handleFrameMessage() throws Exception { } @Test - public void handleFrameMessageWhenNotOpen() throws Exception { + void handleFrameMessageWhenNotOpen() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.close(); reset(this.handler); @@ -116,7 +116,7 @@ public void handleFrameMessageWhenNotOpen() throws Exception { } @Test - public void handleFrameMessageWithBadData() throws Exception { + void handleFrameMessageWithBadData() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.handleFrame("a['bad data"); assertThat(this.session.isOpen()).isFalse(); @@ -126,7 +126,7 @@ public void handleFrameMessageWithBadData() throws Exception { } @Test - public void handleFrameMessageWithWebSocketHandlerException() throws Exception { + void handleFrameMessageWithWebSocketHandlerException() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); willThrow(new IllegalStateException("Fake error")).given(this.handler) .handleMessage(this.session, new TextMessage("foo")); @@ -141,7 +141,7 @@ public void handleFrameMessageWithWebSocketHandlerException() throws Exception { } @Test - public void handleFrameClose() throws Exception { + void handleFrameClose() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.handleFrame(SockJsFrame.closeFrame(1007, "").getContent()); assertThat(this.session.isOpen()).isFalse(); @@ -151,7 +151,7 @@ public void handleFrameClose() throws Exception { } @Test - public void handleTransportError() throws Exception { + void handleTransportError() throws Exception { final IllegalStateException ex = new IllegalStateException("Fake error"); this.session.handleTransportError(ex); verify(this.handler).handleTransportError(this.session, ex); @@ -159,7 +159,7 @@ public void handleTransportError() throws Exception { } @Test - public void afterTransportClosed() throws Exception { + void afterTransportClosed() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.afterTransportClosed(CloseStatus.SERVER_ERROR); assertThat(this.session.isOpen()).isFalse(); @@ -169,7 +169,7 @@ public void afterTransportClosed() throws Exception { } @Test - public void close() throws Exception { + void close() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.close(); assertThat(this.session.isOpen()).isFalse(); @@ -179,14 +179,14 @@ public void close() throws Exception { } @Test - public void closeWithStatus() throws Exception { + void closeWithStatus() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.close(new CloseStatus(3000, "reason")); assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(3000, "reason")); } @Test - public void closeWithNullStatus() throws Exception { + void closeWithNullStatus() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThatIllegalArgumentException().isThrownBy(() -> this.session.close(null)) @@ -194,7 +194,7 @@ public void closeWithNullStatus() throws Exception { } @Test - public void closeWithStatusOutOfRange() throws Exception { + void closeWithStatusOutOfRange() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); assertThatIllegalArgumentException().isThrownBy(() -> this.session.close(new CloseStatus(2999, "reason"))) @@ -202,13 +202,13 @@ public void closeWithStatusOutOfRange() throws Exception { } @Test - public void timeoutTask() { + void timeoutTask() { this.session.getTimeoutTask().run(); assertThat(this.session.disconnectStatus).isEqualTo(new CloseStatus(2007, "Transport timed out")); } @Test - public void send() throws Exception { + void send() throws Exception { this.session.handleFrame(SockJsFrame.openFrame().getContent()); this.session.sendMessage(new TextMessage("foo")); assertThat(this.session.sentMessage).isEqualTo(new TextMessage("[\"foo\"]")); 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 4961c9651890..4172bf55e0b0 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 @@ -45,10 +45,9 @@ * * @author Rossen Stoyanchev */ -public class DefaultTransportRequestTests { - - private static final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec(); +class DefaultTransportRequestTests { + private final Jackson2SockJsMessageCodec CODEC = new Jackson2SockJsMessageCodec(); private CompletableFuture connectFuture; @@ -61,7 +60,7 @@ public class DefaultTransportRequestTests { @SuppressWarnings("unchecked") @BeforeEach - public void setup() throws Exception { + void setup() { this.connectCallback = mock(BiConsumer.class); this.connectFuture = new CompletableFuture<>(); this.connectFuture.whenComplete(this.connectCallback); @@ -71,7 +70,7 @@ public void setup() throws Exception { @Test - public void connect() throws Exception { + void connect() throws Exception { DefaultTransportRequest request = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); request.connect(null, this.connectFuture); WebSocketSession session = mock(WebSocketSession.class); @@ -80,7 +79,7 @@ public void connect() throws Exception { } @Test - public void fallbackAfterTransportError() throws Exception { + void fallbackAfterTransportError() { DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); DefaultTransportRequest request2 = createTransportRequest(this.xhrTransport, TransportType.XHR_STREAMING); request1.setFallbackRequest(request2); @@ -100,7 +99,7 @@ public void fallbackAfterTransportError() throws Exception { } @Test - public void fallbackAfterTimeout() throws Exception { + void fallbackAfterTimeout() { TaskScheduler scheduler = mock(TaskScheduler.class); Runnable sessionCleanupTask = mock(Runnable.class); DefaultTransportRequest request1 = createTransportRequest(this.webSocketTransport, TransportType.WEBSOCKET); @@ -123,8 +122,8 @@ public void fallbackAfterTimeout() throws Exception { verify(sessionCleanupTask).run(); } - protected DefaultTransportRequest createTransportRequest(Transport transport, TransportType type) throws Exception { - SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com")); + protected DefaultTransportRequest createTransportRequest(Transport transport, TransportType type) { + SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com")); return new DefaultTransportRequest(urlInfo, new HttpHeaders(), new HttpHeaders(), transport, type, CODEC); } 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 3d2fafa336ab..cffdec9d61b9 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 @@ -130,7 +130,7 @@ void connectReceiveAndCloseWithStompFrame() throws Exception { @Test @SuppressWarnings("deprecation") - void connectFailure() throws Exception { + void connectFailure() { final HttpServerErrorException expected = new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR); RestOperations restTemplate = mock(RestOperations.class); given(restTemplate.execute((URI) any(), eq(HttpMethod.POST), any(), any())).willThrow(expected); @@ -180,18 +180,18 @@ void responseClosedAfterDisconnected() throws Exception { @SuppressWarnings("deprecation") private org.springframework.util.concurrent.ListenableFuture connect( - ClientHttpResponse... responses) throws Exception { + ClientHttpResponse... responses) { return connect(new TestRestTemplate(responses)); } @SuppressWarnings("deprecation") private org.springframework.util.concurrent.ListenableFuture connect( - RestOperations restTemplate, ClientHttpResponse... responses) throws Exception { + RestOperations restTemplate, ClientHttpResponse... responses) { RestTemplateXhrTransport transport = new RestTemplateXhrTransport(restTemplate); transport.setTaskExecutor(new SyncTaskExecutor()); - SockJsUrlInfo urlInfo = new SockJsUrlInfo(new URI("https://example.com")); + SockJsUrlInfo urlInfo = new SockJsUrlInfo(URI.create("https://example.com")); HttpHeaders headers = new HttpHeaders(); headers.add("h-foo", "h-bar"); TransportRequest request = new DefaultTransportRequest(urlInfo, headers, headers, 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 acd994261a8d..1baed5cc53ad 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 @@ -72,7 +72,7 @@ void setup() { @Test @SuppressWarnings("deprecation") - void connectWebSocket() throws Exception { + void connectWebSocket() { setupInfoRequest(true); this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback); assertThat(this.webSocketTransport.invoked()).isTrue(); @@ -94,7 +94,7 @@ void connectWebSocketDisabled() throws URISyntaxException { @Test @SuppressWarnings("deprecation") - void connectXhrStreamingDisabled() throws Exception { + void connectXhrStreamingDisabled() { setupInfoRequest(false); this.xhrTransport.setStreamingDisabled(true); this.sockJsClient.doHandshake(handler, URL).addCallback(this.connectCallback); @@ -105,14 +105,14 @@ void connectXhrStreamingDisabled() throws Exception { @Test // SPR-13254 @SuppressWarnings("deprecation") - void connectWithHandshakeHeaders() throws Exception { + void connectWithHandshakeHeaders() { ArgumentCaptor headersCaptor = setupInfoRequest(false); this.xhrTransport.setStreamingDisabled(true); WebSocketHttpHeaders headers = new WebSocketHttpHeaders(); headers.set("foo", "bar"); headers.set("auth", "123"); - this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback); + this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback); HttpHeaders httpHeaders = headersCaptor.getValue(); assertThat(httpHeaders).hasSize(2); @@ -127,7 +127,7 @@ void connectWithHandshakeHeaders() throws Exception { @Test @SuppressWarnings("deprecation") - void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception { + void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() { ArgumentCaptor headersCaptor = setupInfoRequest(false); this.xhrTransport.setStreamingDisabled(true); @@ -135,7 +135,7 @@ void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception { headers.set("foo", "bar"); headers.set("auth", "123"); this.sockJsClient.setHttpHeaderNames("auth"); - this.sockJsClient.doHandshake(handler, headers, new URI(URL)).addCallback(this.connectCallback); + this.sockJsClient.doHandshake(handler, headers, URI.create(URL)).addCallback(this.connectCallback); assertThat(headersCaptor.getValue()).hasSize(1); assertThat(headersCaptor.getValue().getFirst("auth")).isEqualTo("123"); @@ -145,7 +145,7 @@ void connectAndUseSubsetOfHandshakeHeadersForHttpRequests() throws Exception { @Test @SuppressWarnings("deprecation") - void connectSockJsInfo() throws Exception { + void connectSockJsInfo() { setupInfoRequest(true); this.sockJsClient.doHandshake(handler, URL); verify(this.infoReceiver, times(1)).executeInfoRequest(any(), any()); @@ -153,7 +153,7 @@ void connectSockJsInfo() throws Exception { @Test @SuppressWarnings("deprecation") - void connectSockJsInfoCached() throws Exception { + void connectSockJsInfoCached() { setupInfoRequest(true); this.sockJsClient.doHandshake(handler, URL); this.sockJsClient.doHandshake(handler, URL); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java index 49fd50b027e9..404e2f2176eb 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfoTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 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,15 +35,15 @@ class SockJsUrlInfoTests { @Test - void serverId() throws Exception { - SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); + void serverId() { + SockJsUrlInfo info = new SockJsUrlInfo(URI.create("https://example.com")); int serverId = Integer.parseInt(info.getServerId()); assertThat(serverId).isGreaterThanOrEqualTo(0).isLessThan(1000); } @Test - void sessionId() throws Exception { - SockJsUrlInfo info = new SockJsUrlInfo(new URI("https://example.com")); + void sessionId() { + SockJsUrlInfo info = new SockJsUrlInfo(URI.create("https://example.com")); assertThat(info.getSessionId()).as("Invalid sessionId: " + info.getSessionId()).hasSize(32); } @@ -54,9 +54,9 @@ void sessionId() throws Exception { ws, http wss, https """) - void infoUrl(String scheme, String expectedScheme) throws Exception { - SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); - assertThat(info.getInfoUrl()).isEqualTo(new URI(expectedScheme + "://example.com/info")); + void infoUrl(String scheme, String expectedScheme) { + SockJsUrlInfo info = new SockJsUrlInfo(URI.create(scheme + "://example.com")); + assertThat(info.getInfoUrl()).isEqualTo(URI.create(expectedScheme + "://example.com/info")); } @ParameterizedTest @@ -70,12 +70,12 @@ void infoUrl(String scheme, String expectedScheme) throws Exception { wss, https, XHR_STREAMING wss, wss, WEBSOCKET """) - void transportUrl(String scheme, String expectedScheme, TransportType transportType) throws Exception { - SockJsUrlInfo info = new SockJsUrlInfo(new URI(scheme + "://example.com")); + void transportUrl(String scheme, String expectedScheme, TransportType transportType) { + SockJsUrlInfo info = new SockJsUrlInfo(URI.create(scheme + "://example.com")); String serverId = info.getServerId(); String sessionId = info.getSessionId(); String transport = transportType.toString().toLowerCase(); - URI expected = new URI(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); + URI expected = URI.create(expectedScheme + "://example.com/" + serverId + "/" + sessionId + "/" + transport); assertThat(info.getTransportUrl(transportType)).isEqualTo(expected); } diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/XhrTransportTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/XhrTransportTests.java index 3685119be392..788281d72759 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/XhrTransportTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/sockjs/client/XhrTransportTests.java @@ -46,28 +46,28 @@ class XhrTransportTests { @Test - void infoResponse() throws Exception { + void infoResponse() { TestXhrTransport transport = new TestXhrTransport(); transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.OK); - assertThat(transport.executeInfoRequest(new URI("https://example.com/info"), null)).isEqualTo("body"); + assertThat(transport.executeInfoRequest(URI.create("https://example.com/info"), null)).isEqualTo("body"); } @Test - void infoResponseError() throws Exception { + void infoResponseError() { TestXhrTransport transport = new TestXhrTransport(); transport.infoResponseToReturn = new ResponseEntity<>("body", HttpStatus.BAD_REQUEST); assertThatExceptionOfType(HttpServerErrorException.class).isThrownBy(() -> - transport.executeInfoRequest(new URI("https://example.com/info"), null)); + transport.executeInfoRequest(URI.create("https://example.com/info"), null)); } @Test - void sendMessage() throws Exception { + void sendMessage() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set("foo", "bar"); requestHeaders.setContentType(MediaType.APPLICATION_JSON); TestXhrTransport transport = new TestXhrTransport(); transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.NO_CONTENT); - URI url = new URI("https://example.com"); + URI url = URI.create("https://example.com"); transport.executeSendRequest(url, requestHeaders, new TextMessage("payload")); assertThat(transport.actualSendRequestHeaders).hasSize(2); assertThat(transport.actualSendRequestHeaders.getFirst("foo")).isEqualTo("bar"); @@ -75,22 +75,22 @@ void sendMessage() throws Exception { } @Test - void sendMessageError() throws Exception { + void sendMessageError() { TestXhrTransport transport = new TestXhrTransport(); transport.sendMessageResponseToReturn = new ResponseEntity<>(HttpStatus.BAD_REQUEST); - URI url = new URI("https://example.com"); + URI url = URI.create("https://example.com"); assertThatExceptionOfType(HttpServerErrorException.class).isThrownBy(() -> transport.executeSendRequest(url, new HttpHeaders(), new TextMessage("payload"))); } @Test @SuppressWarnings("deprecation") - void connect() throws Exception { + void connect() { HttpHeaders handshakeHeaders = new HttpHeaders(); handshakeHeaders.setOrigin("foo"); TransportRequest request = mock(TransportRequest.class); - given(request.getSockJsUrlInfo()).willReturn(new SockJsUrlInfo(new URI("https://example.com"))); + given(request.getSockJsUrlInfo()).willReturn(new SockJsUrlInfo(URI.create("https://example.com"))); given(request.getHandshakeHeaders()).willReturn(handshakeHeaders); given(request.getHttpRequestHeaders()).willReturn(new HttpHeaders());