Polishing
See gh-28189
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -130,7 +131,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
@Test
|
||||
public void resolveArgumentParameterizedType() throws Exception {
|
||||
String content = "[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -150,7 +151,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
|
||||
String content = "fruit=apple&vegetable=kale";
|
||||
this.servletRequest.setMethod("GET");
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -169,7 +170,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
@Test
|
||||
public void resolveArgumentClassJson() throws Exception {
|
||||
String content = "{\"name\" : \"Jad\"}";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType("application/json");
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -186,7 +187,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
@Test
|
||||
public void resolveArgumentClassString() throws Exception {
|
||||
String content = "foobarbaz";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType("application/json");
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -201,7 +202,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
@Test // SPR-9942
|
||||
public void resolveArgumentRequiredNoContent() throws Exception {
|
||||
public void resolveArgumentRequiredNoContent() {
|
||||
this.servletRequest.setContent(new byte[0]);
|
||||
this.servletRequest.setContentType("text/plain");
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -230,7 +231,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
|
||||
|
||||
String content = "{\"name\" : \"Jad\"}";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -250,7 +251,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
|
||||
|
||||
String content = "[{\"name\" : \"Jad\"}, {\"name\" : \"Robert\"}]";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -273,7 +274,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
MethodParameter methodParam = handlerMethod.getMethodParameters()[0];
|
||||
|
||||
String content = "{\"name\" : \"Jad\"}";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
@@ -609,7 +610,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
@Test // SPR-12501
|
||||
public void resolveArgumentWithJacksonJsonView() throws Exception {
|
||||
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Method method = JacksonController.class.getMethod("handleRequestBody", JacksonViewBean.class);
|
||||
@@ -634,7 +635,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
@Test // SPR-12501
|
||||
public void resolveHttpEntityArgumentWithJacksonJsonView() throws Exception {
|
||||
String content = "{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Method method = JacksonController.class.getMethod("handleHttpEntity", HttpEntity.class);
|
||||
@@ -664,7 +665,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
"<withView1>with</withView1>" +
|
||||
"<withView2>with</withView2>" +
|
||||
"<withoutView>without</withoutView></root>";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);
|
||||
|
||||
Method method = JacksonController.class.getMethod("handleRequestBody", JacksonViewBean.class);
|
||||
@@ -692,7 +693,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
"<withView1>with</withView1>" +
|
||||
"<withView2>with</withView2>" +
|
||||
"<withoutView>without</withoutView></root>";
|
||||
this.servletRequest.setContent(content.getBytes("UTF-8"));
|
||||
this.servletRequest.setContent(content.getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_XML_VALUE);
|
||||
|
||||
Method method = JacksonController.class.getMethod("handleHttpEntity", HttpEntity.class);
|
||||
@@ -774,7 +775,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
|
||||
@Test // SPR-14520
|
||||
public void resolveArgumentTypeVariableWithGenericInterface() throws Exception {
|
||||
this.servletRequest.setContent("\"foo\"".getBytes("UTF-8"));
|
||||
this.servletRequest.setContent("\"foo\"".getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Method method = MyControllerImplementingInterface.class.getMethod("handle", Object.class);
|
||||
@@ -794,7 +795,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
|
||||
@Test // gh-24127
|
||||
public void resolveArgumentTypeVariableWithGenericInterfaceAndSubclass() throws Exception {
|
||||
this.servletRequest.setContent("\"foo\"".getBytes("UTF-8"));
|
||||
this.servletRequest.setContent("\"foo\"".getBytes(StandardCharsets.UTF_8));
|
||||
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
||||
|
||||
Method method = SubControllerImplementingInterface.class.getMethod("handle", Object.class);
|
||||
@@ -836,6 +837,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
String handle(
|
||||
@RequestBody List<SimpleBean> list,
|
||||
@RequestBody SimpleBean simpleBean,
|
||||
@@ -845,19 +847,23 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
Resource getImage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
ProblemDetail handleAndReturnProblemDetail() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@RequestMapping
|
||||
OutputStream handleAndReturnOutputStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
SimpleBean getSimpleBean() {
|
||||
return null;
|
||||
}
|
||||
@@ -895,7 +901,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "serial" })
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
private static class SimpleBean implements Identifiable {
|
||||
|
||||
private Long id;
|
||||
@@ -922,7 +928,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
private final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
private static final class ValidatingBinderFactory implements WebDataBinderFactory {
|
||||
|
||||
@Override
|
||||
public WebDataBinder createBinder(NativeWebRequest request, @Nullable Object target, String objectName) {
|
||||
@@ -943,6 +949,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@RequestMapping
|
||||
public CharSequence handleWithCharSequence() {
|
||||
return null;
|
||||
@@ -965,6 +972,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
private interface MyJacksonView2 {}
|
||||
|
||||
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
private static class JacksonViewBean {
|
||||
|
||||
@JsonView(MyJacksonView1.class)
|
||||
@@ -983,6 +991,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
this.withView1 = withView1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWithView2() {
|
||||
return withView2;
|
||||
}
|
||||
@@ -991,6 +1000,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
this.withView2 = withView2;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWithoutView() {
|
||||
return withoutView;
|
||||
}
|
||||
@@ -1001,7 +1011,8 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
|
||||
@SuppressWarnings("NotNullFieldNotInitialized")
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
|
||||
public static class ParentClass {
|
||||
|
||||
private String parentProperty;
|
||||
@@ -1092,6 +1103,7 @@ public class RequestResponseBodyMethodProcessorTests {
|
||||
return bean;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@RequestMapping
|
||||
@ResponseBody
|
||||
public JacksonViewBean handleHttpEntity(@JsonView(MyJacksonView1.class) HttpEntity<JacksonViewBean> entity) {
|
||||
|
||||
Reference in New Issue
Block a user