Skip to content

Commit 5f2a6fd

Browse files
imkulwantsbrannen
authored andcommitted
Use List.of() instead of Arrays.asList() where appropriate
See gh-29408
1 parent eec3c6f commit 5f2a6fd

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.web.socket.client;
1818

1919
import java.net.URI;
20-
import java.util.Arrays;
2120
import java.util.List;
2221
import java.util.concurrent.CompletableFuture;
2322

@@ -45,7 +44,7 @@ public class WebSocketConnectionManagerTests {
4544

4645
@Test
4746
public void openConnection() throws Exception {
48-
List<String> subprotocols = Arrays.asList("abc");
47+
List<String> subprotocols = List.of("abc");
4948

5049
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
5150
WebSocketHandler handler = new TextWebSocketHandler();

spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistrationTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.web.socket.config.annotation;
1818

19-
import java.util.Arrays;
2019
import java.util.List;
2120
import java.util.Map;
2221

@@ -72,7 +71,7 @@ public void minimalRegistration() {
7271
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
7372
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getWebSocketHandler()).isNotNull();
7473
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getHandshakeInterceptors().size()).isEqualTo(1);
75-
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
74+
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
7675
}
7776

7877
@Test
@@ -190,7 +189,7 @@ public void handshakeHandlerAndInterceptor() {
190189
assertThat(mappings.size()).isEqualTo(1);
191190

192191
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
193-
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
192+
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
194193

195194
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
196195
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -214,7 +213,7 @@ public void handshakeHandlerAndInterceptorWithAllowedOrigins() {
214213
assertThat(mappings.size()).isEqualTo(1);
215214

216215
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
217-
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
216+
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
218217

219218
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
220219
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -238,7 +237,7 @@ public void handshakeHandlerInterceptorWithSockJsService() {
238237
assertThat(mappings.size()).isEqualTo(1);
239238

240239
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
241-
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
240+
assertThat(entry.getValue()).isEqualTo(List.of("/foo/**"));
242241

243242
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
244243
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -270,7 +269,7 @@ public void handshakeHandlerInterceptorWithSockJsServiceAndAllowedOrigins() {
270269
assertThat(mappings.size()).isEqualTo(1);
271270

272271
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
273-
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
272+
assertThat(entry.getValue()).isEqualTo(List.of("/foo/**"));
274273

275274
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
276275
assertThat(requestHandler.getWebSocketHandler()).isNotNull();

spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.web.socket.messaging;
1818

1919
import java.util.Arrays;
20+
import java.util.List;
2021
import java.util.Map;
2122

2223
import org.junit.jupiter.api.BeforeEach;
@@ -70,7 +71,7 @@ public class SubProtocolWebSocketHandlerTests {
7071
public void setup() {
7172
this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel);
7273
given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp"));
73-
given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
74+
given(mqttHandler.getSupportedProtocols()).willReturn(List.of("MQTT"));
7475
this.session = new TestWebSocketSession();
7576
this.session.setId("1");
7677
this.session.setOpen(true);
@@ -133,7 +134,7 @@ public void emptySubProtocol() throws Exception {
133134

134135
@Test
135136
public void noSubProtocolOneHandler() throws Exception {
136-
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler));
137+
this.webSocketHandler.setProtocolHandlers(List.of(stompHandler));
137138
this.webSocketHandler.afterConnectionEstablished(session);
138139

139140
verify(this.stompHandler).afterSessionStarted(
@@ -164,7 +165,7 @@ public void checkSession() throws Exception {
164165
session1.setAcceptedProtocol("v12.stomp");
165166
session2.setAcceptedProtocol("v12.stomp");
166167

167-
this.webSocketHandler.setProtocolHandlers(Arrays.asList(this.stompHandler));
168+
this.webSocketHandler.setProtocolHandlers(List.of(this.stompHandler));
168169
this.webSocketHandler.afterConnectionEstablished(session1);
169170
this.webSocketHandler.afterConnectionEstablished(session2);
170171

spring-websocket/src/test/java/org/springframework/web/socket/server/support/OriginHandshakeInterceptorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void sameOriginMatchWithEmptyAllowedOrigins() throws Exception {
120120
public void sameOriginMatchWithAllowedOrigins() throws Exception {
121121
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.example");
122122
this.servletRequest.setServerName("mydomain2.example");
123-
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.example"));
123+
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(List.of("http://mydomain1.example"));
124124
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
125125
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo(servletResponse.getStatus());
126126
}

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/handler/DefaultSockJsServiceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void handleTransportRequestXhrAllowedOriginsNoMatch() throws Exception {
187187
public void handleTransportRequestXhrSameOrigin() throws Exception {
188188
String sockJsPath = sessionUrlPrefix + "xhr";
189189
setRequest("POST", sockJsPrefix + sockJsPath);
190-
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example"));
190+
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
191191
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.example");
192192
this.servletRequest.setServerName("mydomain2.example");
193193
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@@ -199,7 +199,7 @@ public void handleTransportRequestXhrSameOrigin() throws Exception {
199199
public void handleInvalidTransportType() throws Exception {
200200
String sockJsPath = sessionUrlPrefix + "invalid";
201201
setRequest("POST", sockJsPrefix + sockJsPath);
202-
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example"));
202+
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
203203
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.example");
204204
this.servletRequest.setServerName("mydomain2.example");
205205
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/session/WebSocketServerSockJsSessionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void isActive() throws Exception {
7979
public void afterSessionInitialized() throws Exception {
8080
this.session.initializeDelegateSession(this.webSocketSession);
8181
assertThat(this.webSocketSession.getSentMessages()).isEqualTo(Collections.singletonList(new TextMessage("o")));
82-
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(Arrays.asList("schedule"));
82+
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(List.of("schedule"));
8383
verify(this.webSocketHandler).afterConnectionEstablished(this.session);
8484
verifyNoMoreInteractions(this.taskScheduler, this.webSocketHandler);
8585
}

0 commit comments

Comments
 (0)