diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java index 725a6cb55b18..463922c78eb6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java @@ -106,7 +106,7 @@ public DefaultResponseCreator body(Resource resource) { /** * Set the {@code Content-Type} header. */ - public DefaultResponseCreator contentType(MediaType mediaType) { + public DefaultResponseCreator contentType(@Nullable MediaType mediaType) { this.headers.setContentType(mediaType); return this; } @@ -114,7 +114,7 @@ public DefaultResponseCreator contentType(MediaType mediaType) { /** * Set the {@code Location} header. */ - public DefaultResponseCreator location(URI location) { + public DefaultResponseCreator location(@Nullable URI location) { this.headers.setLocation(location); return this; } @@ -123,7 +123,7 @@ public DefaultResponseCreator location(URI location) { * Add a response header with one or more values. * @since 6.0 */ - public DefaultResponseCreator header(String name, String ... headerValues) { + public DefaultResponseCreator header(String name, @Nullable String... headerValues) { for (String headerValue : headerValues) { this.headers.add(name, headerValue); } diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java b/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java index 06530b2239a6..ff5d490b8cc4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/MockRestResponseCreators.java @@ -54,8 +54,7 @@ public static DefaultResponseCreator withSuccess() { * @param contentType the type of the content (may be {@code null}) */ public static DefaultResponseCreator withSuccess(String body, @Nullable MediaType contentType) { - DefaultResponseCreator creator = new DefaultResponseCreator(HttpStatus.OK).body(body); - return (contentType != null ? creator.contentType(contentType) : creator); + return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(contentType); } /** @@ -64,8 +63,7 @@ public static DefaultResponseCreator withSuccess(String body, @Nullable MediaTyp * @param contentType the type of the content (may be {@code null}) */ public static DefaultResponseCreator withSuccess(byte[] body, @Nullable MediaType contentType) { - DefaultResponseCreator creator = new DefaultResponseCreator(HttpStatus.OK).body(body); - return (contentType != null ? creator.contentType(contentType) : creator); + return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(contentType); } /** @@ -74,8 +72,7 @@ public static DefaultResponseCreator withSuccess(byte[] body, @Nullable MediaTyp * @param contentType the type of the content (may be {@code null}) */ public static DefaultResponseCreator withSuccess(Resource body, @Nullable MediaType contentType) { - DefaultResponseCreator creator = new DefaultResponseCreator(HttpStatus.OK).body(body); - return (contentType != null ? creator.contentType(contentType) : creator); + return new DefaultResponseCreator(HttpStatus.OK).body(body).contentType(contentType); } /**