Polish tests
Closes gh-26708
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -31,7 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class HttpEntityTests {
|
||||
|
||||
@Test
|
||||
public void noHeaders() {
|
||||
void noHeaders() {
|
||||
String body = "foo";
|
||||
HttpEntity<String> entity = new HttpEntity<>(body);
|
||||
assertThat(entity.getBody()).isSameAs(body);
|
||||
@@ -39,7 +39,7 @@ public class HttpEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHeaders() {
|
||||
void httpHeaders() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||
String body = "foo";
|
||||
@@ -50,7 +50,7 @@ public class HttpEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiValueMap() {
|
||||
void multiValueMap() {
|
||||
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
|
||||
map.set("Content-Type", "text/plain");
|
||||
String body = "foo";
|
||||
@@ -61,30 +61,30 @@ public class HttpEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
void testEquals() {
|
||||
MultiValueMap<String, String> map1 = new LinkedMultiValueMap<>();
|
||||
map1.set("Content-Type", "text/plain");
|
||||
|
||||
MultiValueMap<String, String> map2 = new LinkedMultiValueMap<>();
|
||||
map2.set("Content-Type", "application/json");
|
||||
|
||||
assertThat(new HttpEntity<>().equals(new HttpEntity<Object>())).isTrue();
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>())).isFalse();
|
||||
assertThat(new HttpEntity<>().equals(new HttpEntity<Object>(map2))).isFalse();
|
||||
assertThat(new HttpEntity<>().equals(new HttpEntity<>())).isTrue();
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>())).isFalse();
|
||||
assertThat(new HttpEntity<>().equals(new HttpEntity<>(map2))).isFalse();
|
||||
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>(map1))).isTrue();
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>(map2))).isFalse();
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map1))).isTrue();
|
||||
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map2))).isFalse();
|
||||
|
||||
assertThat(new HttpEntity<String>(null, null).equals(new HttpEntity<String>(null, null))).isTrue();
|
||||
assertThat(new HttpEntity<>("foo", null).equals(new HttpEntity<String>(null, null))).isFalse();
|
||||
assertThat(new HttpEntity<String>(null, null).equals(new HttpEntity<>("bar", null))).isFalse();
|
||||
|
||||
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<String>("foo", map1))).isTrue();
|
||||
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<String>("bar", map1))).isFalse();
|
||||
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("foo", map1))).isTrue();
|
||||
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("bar", map1))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseEntity() {
|
||||
void responseEntity() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||
String body = "foo";
|
||||
@@ -104,7 +104,7 @@ public class HttpEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestEntity() throws Exception {
|
||||
void requestEntity() throws Exception {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.TEXT_PLAIN);
|
||||
String body = "foo";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2021 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.
|
||||
@@ -45,20 +45,20 @@ public class ServletServerHttpRequestTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void create() {
|
||||
void create() {
|
||||
mockRequest = new MockHttpServletRequest();
|
||||
request = new ServletServerHttpRequest(mockRequest);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getMethod() {
|
||||
void getMethod() {
|
||||
mockRequest.setMethod("POST");
|
||||
assertThat(request.getMethod()).as("Invalid method").isEqualTo(HttpMethod.POST);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUriForSimplePath() throws URISyntaxException {
|
||||
void getUriForSimplePath() throws URISyntaxException {
|
||||
URI uri = new URI("https://example.com/path");
|
||||
mockRequest.setScheme(uri.getScheme());
|
||||
mockRequest.setServerName(uri.getHost());
|
||||
@@ -69,7 +69,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUriWithQueryString() throws URISyntaxException {
|
||||
void getUriWithQueryString() throws URISyntaxException {
|
||||
URI uri = new URI("https://example.com/path?query");
|
||||
mockRequest.setScheme(uri.getScheme());
|
||||
mockRequest.setServerName(uri.getHost());
|
||||
@@ -80,7 +80,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test // SPR-16414
|
||||
public void getUriWithQueryParam() throws URISyntaxException {
|
||||
void getUriWithQueryParam() throws URISyntaxException {
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(443);
|
||||
mockRequest.setServerName("example.com");
|
||||
@@ -90,7 +90,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test // SPR-16414
|
||||
public void getUriWithMalformedQueryParam() throws URISyntaxException {
|
||||
void getUriWithMalformedQueryParam() throws URISyntaxException {
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(443);
|
||||
mockRequest.setServerName("example.com");
|
||||
@@ -100,7 +100,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test // SPR-13876
|
||||
public void getUriWithEncoding() throws URISyntaxException {
|
||||
void getUriWithEncoding() throws URISyntaxException {
|
||||
URI uri = new URI("https://example.com/%E4%B8%AD%E6%96%87" +
|
||||
"?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework");
|
||||
mockRequest.setScheme(uri.getScheme());
|
||||
@@ -112,7 +112,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeaders() {
|
||||
void getHeaders() {
|
||||
String headerName = "MyHeader";
|
||||
String headerValue1 = "value1";
|
||||
String headerValue2 = "value2";
|
||||
@@ -132,7 +132,7 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHeadersWithEmptyContentTypeAndEncoding() {
|
||||
void getHeadersWithEmptyContentTypeAndEncoding() {
|
||||
String headerName = "MyHeader";
|
||||
String headerValue1 = "value1";
|
||||
String headerValue2 = "value2";
|
||||
@@ -152,8 +152,8 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBody() throws IOException {
|
||||
byte[] content = "Hello World".getBytes("UTF-8");
|
||||
void getBody() throws IOException {
|
||||
byte[] content = "Hello World".getBytes(StandardCharsets.UTF_8);
|
||||
mockRequest.setContent(content);
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
@@ -161,16 +161,17 @@ public class ServletServerHttpRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFormBody() throws IOException {
|
||||
void getFormBody() throws IOException {
|
||||
// Charset (SPR-8676)
|
||||
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||
mockRequest.setMethod("POST");
|
||||
mockRequest.addParameter("name 1", "value 1");
|
||||
mockRequest.addParameter("name 2", new String[] {"value 2+1", "value 2+2"});
|
||||
mockRequest.addParameter("name 2", "value 2+1", "value 2+2");
|
||||
mockRequest.addParameter("name 3", (String) null);
|
||||
|
||||
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
|
||||
byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes("UTF-8");
|
||||
byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(
|
||||
StandardCharsets.UTF_8);
|
||||
assertThat(result).as("Invalid content returned").isEqualTo(content);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user