Use List.of() instead of Arrays.asList() where appropriate

See gh-29408
This commit is contained in:
Kulwant Singh
2022-10-31 23:01:16 +01:00
committed by Sam Brannen
parent eec3c6f7bb
commit 5f2a6fd7f1
6 changed files with 14 additions and 15 deletions

View File

@@ -17,7 +17,6 @@
package org.springframework.web.socket.client;
import java.net.URI;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -45,7 +44,7 @@ public class WebSocketConnectionManagerTests {
@Test
public void openConnection() throws Exception {
List<String> subprotocols = Arrays.asList("abc");
List<String> subprotocols = List.of("abc");
TestLifecycleWebSocketClient client = new TestLifecycleWebSocketClient(false);
WebSocketHandler handler = new TextWebSocketHandler();

View File

@@ -16,7 +16,6 @@
package org.springframework.web.socket.config.annotation;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -72,7 +71,7 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getWebSocketHandler()).isNotNull();
assertThat(((WebSocketHttpRequestHandler) entry.getKey()).getHandshakeInterceptors().size()).isEqualTo(1);
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
}
@Test
@@ -190,7 +189,7 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -214,7 +213,7 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo"));
assertThat(entry.getValue()).isEqualTo(List.of("/foo"));
WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -238,7 +237,7 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
assertThat(entry.getValue()).isEqualTo(List.of("/foo/**"));
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();
@@ -270,7 +269,7 @@ public class WebMvcStompWebSocketEndpointRegistrationTests {
assertThat(mappings.size()).isEqualTo(1);
Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
assertThat(entry.getValue()).isEqualTo(Arrays.asList("/foo/**"));
assertThat(entry.getValue()).isEqualTo(List.of("/foo/**"));
SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler) entry.getKey();
assertThat(requestHandler.getWebSocketHandler()).isNotNull();

View File

@@ -17,6 +17,7 @@
package org.springframework.web.socket.messaging;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
@@ -70,7 +71,7 @@ public class SubProtocolWebSocketHandlerTests {
public 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(Arrays.asList("MQTT"));
given(mqttHandler.getSupportedProtocols()).willReturn(List.of("MQTT"));
this.session = new TestWebSocketSession();
this.session.setId("1");
this.session.setOpen(true);
@@ -133,7 +134,7 @@ public class SubProtocolWebSocketHandlerTests {
@Test
public void noSubProtocolOneHandler() throws Exception {
this.webSocketHandler.setProtocolHandlers(Arrays.asList(stompHandler));
this.webSocketHandler.setProtocolHandlers(List.of(stompHandler));
this.webSocketHandler.afterConnectionEstablished(session);
verify(this.stompHandler).afterSessionStarted(
@@ -164,7 +165,7 @@ public class SubProtocolWebSocketHandlerTests {
session1.setAcceptedProtocol("v12.stomp");
session2.setAcceptedProtocol("v12.stomp");
this.webSocketHandler.setProtocolHandlers(Arrays.asList(this.stompHandler));
this.webSocketHandler.setProtocolHandlers(List.of(this.stompHandler));
this.webSocketHandler.afterConnectionEstablished(session1);
this.webSocketHandler.afterConnectionEstablished(session2);

View File

@@ -120,7 +120,7 @@ public class OriginHandshakeInterceptorTests extends AbstractHttpRequestTests {
public void sameOriginMatchWithAllowedOrigins() throws Exception {
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain2.example");
this.servletRequest.setServerName("mydomain2.example");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(Arrays.asList("http://mydomain1.example"));
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor(List.of("http://mydomain1.example"));
assertThat(interceptor.beforeHandshake(request, response, wsHandler, attributes)).isTrue();
assertThat(HttpStatus.FORBIDDEN.value()).isNotEqualTo(servletResponse.getStatus());
}

View File

@@ -187,7 +187,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
public void handleTransportRequestXhrSameOrigin() throws Exception {
String sockJsPath = sessionUrlPrefix + "xhr";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example"));
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain1.example");
this.servletRequest.setServerName("mydomain2.example");
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);
@@ -199,7 +199,7 @@ public class DefaultSockJsServiceTests extends AbstractHttpRequestTests {
public void handleInvalidTransportType() throws Exception {
String sockJsPath = sessionUrlPrefix + "invalid";
setRequest("POST", sockJsPrefix + sockJsPath);
this.service.setAllowedOrigins(Arrays.asList("https://mydomain1.example"));
this.service.setAllowedOrigins(List.of("https://mydomain1.example"));
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "https://mydomain2.example");
this.servletRequest.setServerName("mydomain2.example");
this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler);

View File

@@ -79,7 +79,7 @@ public class WebSocketServerSockJsSessionTests extends AbstractSockJsSessionTest
public void afterSessionInitialized() throws Exception {
this.session.initializeDelegateSession(this.webSocketSession);
assertThat(this.webSocketSession.getSentMessages()).isEqualTo(Collections.singletonList(new TextMessage("o")));
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(Arrays.asList("schedule"));
assertThat(this.session.heartbeatSchedulingEvents).isEqualTo(List.of("schedule"));
verify(this.webSocketHandler).afterConnectionEstablished(this.session);
verifyNoMoreInteractions(this.taskScheduler, this.webSocketHandler);
}