Use StandardCharsets

See gh-29408
This commit is contained in:
Kulwant Singh
2022-10-31 22:49:29 +01:00
committed by Sam Brannen
parent c091bbdeaa
commit bd57d860d2

View File

@@ -26,6 +26,8 @@ import org.springframework.web.socket.sockjs.transport.session.AbstractSockJsSes
import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig; import org.springframework.web.socket.sockjs.transport.session.StubSockJsServiceConfig;
import org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession; import org.springframework.web.socket.sockjs.transport.session.TestHttpSockJsSession;
import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -44,7 +46,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
@Test @Test
public void readMessagesXhr() throws Exception { public void readMessagesXhr() throws Exception {
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8")); this.servletRequest.setContent("[\"x\"]".getBytes(StandardCharsets.UTF_8));
handleRequest(new XhrReceivingTransportHandler()); handleRequest(new XhrReceivingTransportHandler());
assertThat(this.servletResponse.getStatus()).isEqualTo(204); assertThat(this.servletResponse.getStatus()).isEqualTo(204);
@@ -52,10 +54,10 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
@Test @Test
public void readMessagesBadContent() throws Exception { public void readMessagesBadContent() throws Exception {
this.servletRequest.setContent("".getBytes("UTF-8")); this.servletRequest.setContent("".getBytes(StandardCharsets.UTF_8));
handleRequestAndExpectFailure(); handleRequestAndExpectFailure();
this.servletRequest.setContent("[\"x]".getBytes("UTF-8")); this.servletRequest.setContent("[\"x]".getBytes(StandardCharsets.UTF_8));
handleRequestAndExpectFailure(); handleRequestAndExpectFailure();
} }
@@ -69,7 +71,7 @@ public class HttpReceivingTransportHandlerTests extends AbstractHttpRequestTests
@Test @Test
public void delegateMessageException() throws Exception { public void delegateMessageException() throws Exception {
StubSockJsServiceConfig sockJsConfig = new StubSockJsServiceConfig(); StubSockJsServiceConfig sockJsConfig = new StubSockJsServiceConfig();
this.servletRequest.setContent("[\"x\"]".getBytes("UTF-8")); this.servletRequest.setContent("[\"x\"]".getBytes(StandardCharsets.UTF_8));
WebSocketHandler wsHandler = mock(WebSocketHandler.class); WebSocketHandler wsHandler = mock(WebSocketHandler.class);
TestHttpSockJsSession session = new TestHttpSockJsSession("1", sockJsConfig, wsHandler, null); TestHttpSockJsSession session = new TestHttpSockJsSession("1", sockJsConfig, wsHandler, null);