Browse Source

Use URI#create instead of URI constructor where feasible in spring-webflux

pull/29671/head
Sam Brannen 3 years ago
parent
commit
67644a28b6
  1. 25
      spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java
  2. 12
      spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java
  3. 38
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java
  4. 7
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java
  5. 9
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java
  6. 83
      spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java

25
spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilderTests.java

@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
package org.springframework.web.reactive.function.client;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
@ -49,12 +48,12 @@ import static org.springframework.http.HttpMethod.POST; @@ -49,12 +48,12 @@ import static org.springframework.http.HttpMethod.POST;
* Unit tests for {@link DefaultClientRequestBuilder}.
* @author Arjen Poutsma
*/
public class DefaultClientRequestBuilderTests {
class DefaultClientRequestBuilderTests {
private static final URI DEFAULT_URL = URI.create("https://example.com");
@Test
public void from() {
void from() {
ClientRequest other = ClientRequest.create(GET, DEFAULT_URL)
.header("foo", "bar")
.cookie("baz", "qux")
@ -80,7 +79,7 @@ public class DefaultClientRequestBuilderTests { @@ -80,7 +79,7 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void fromCopiesBody() {
void fromCopiesBody() {
String body = "foo";
BodyInserter<String, ClientHttpRequest> inserter = (response, strategies) -> {
byte[] bodyBytes = body.getBytes(UTF_8);
@ -106,7 +105,7 @@ public class DefaultClientRequestBuilderTests { @@ -106,7 +105,7 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void method() {
void method() {
ClientRequest.Builder builder = ClientRequest.create(DELETE, DEFAULT_URL);
assertThat(builder.build().method()).isEqualTo(DELETE);
@ -115,9 +114,9 @@ public class DefaultClientRequestBuilderTests { @@ -115,9 +114,9 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void url() throws URISyntaxException {
URI url1 = new URI("https://example.com/foo");
URI url2 = new URI("https://example.com/bar");
void url() {
URI url1 = URI.create("https://example.com/foo");
URI url2 = URI.create("https://example.com/bar");
ClientRequest.Builder builder = ClientRequest.create(DELETE, url1);
assertThat(builder.build().url()).isEqualTo(url1);
@ -126,13 +125,13 @@ public class DefaultClientRequestBuilderTests { @@ -126,13 +125,13 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void cookie() {
void cookie() {
ClientRequest result = ClientRequest.create(GET, DEFAULT_URL).cookie("foo", "bar").build();
assertThat(result.cookies().getFirst("foo")).isEqualTo("bar");
}
@Test
public void build() {
void build() {
ClientRequest result = ClientRequest.create(GET, DEFAULT_URL)
.header("MyKey", "MyValue")
.cookie("foo", "bar")
@ -155,7 +154,7 @@ public class DefaultClientRequestBuilderTests { @@ -155,7 +154,7 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void bodyInserter() {
void bodyInserter() {
String body = "foo";
BodyInserter<String, ClientHttpRequest> inserter = (response, strategies) -> {
byte[] bodyBytes = body.getBytes(UTF_8);
@ -180,7 +179,7 @@ public class DefaultClientRequestBuilderTests { @@ -180,7 +179,7 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void bodyClass() {
void bodyClass() {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
ClientRequest result = ClientRequest.create(POST, DEFAULT_URL).body(publisher, String.class).build();
@ -199,7 +198,7 @@ public class DefaultClientRequestBuilderTests { @@ -199,7 +198,7 @@ public class DefaultClientRequestBuilderTests {
}
@Test
public void bodyParameterizedTypeReference() {
void bodyParameterizedTypeReference() {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};

12
spring-webflux/src/test/java/org/springframework/web/reactive/result/SimpleUrlHandlerMappingIntegrationTests.java

@ -56,9 +56,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra @@ -56,9 +56,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
@Override
protected HttpHandler createHttpHandler() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(WebConfig.class);
return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac))
.exceptionHandler(new ResponseStatusExceptionHandler())
@ -70,7 +68,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra @@ -70,7 +68,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
void requestToFooHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/foo");
URI url = URI.create("http://localhost:" + this.port + "/foo");
RequestEntity<Void> request = RequestEntity.get(url).build();
@SuppressWarnings("resource")
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@ -83,7 +81,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra @@ -83,7 +81,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
public void requestToBarHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/bar");
URI url = URI.create("http://localhost:" + this.port + "/bar");
RequestEntity<Void> request = RequestEntity.get(url).build();
@SuppressWarnings("resource")
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@ -96,7 +94,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra @@ -96,7 +94,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
void requestToHeaderSettingHandler(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/header");
URI url = URI.create("http://localhost:" + this.port + "/header");
RequestEntity<Void> request = RequestEntity.get(url).build();
@SuppressWarnings("resource")
ResponseEntity<byte[]> response = new RestTemplate().exchange(request, byte[].class);
@ -110,7 +108,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra @@ -110,7 +108,7 @@ class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandlerIntegra
void handlerNotFound(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI url = new URI("http://localhost:" + this.port + "/oops");
URI url = URI.create("http://localhost:" + this.port + "/oops");
RequestEntity<Void> request = RequestEntity.get(url).build();
try {
new RestTemplate().exchange(request, byte[].class);

38
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/AbstractRequestMappingIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@ -66,33 +66,27 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt @@ -66,33 +66,27 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt
}
<T> ResponseEntity<T> performGet(String url, MediaType out, Class<T> type) throws Exception {
<T> ResponseEntity<T> performGet(String url, MediaType out, Class<T> type) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(out));
return getRestTemplate().exchange(prepareGet(url, headers), type);
}
<T> ResponseEntity<T> performGet(String url, HttpHeaders headers, Class<T> type) throws Exception {
<T> ResponseEntity<T> performGet(String url, HttpHeaders headers, Class<T> type) {
return getRestTemplate().exchange(prepareGet(url, headers), type);
}
<T> ResponseEntity<T> performGet(String url, MediaType out, ParameterizedTypeReference<T> type)
throws Exception {
<T> ResponseEntity<T> performGet(String url, MediaType out, ParameterizedTypeReference<T> type) {
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(out));
return this.restTemplate.exchange(prepareGet(url, headers), type);
}
<T> ResponseEntity<T> performOptions(String url, HttpHeaders headers, Class<T> type)
throws Exception {
<T> ResponseEntity<T> performOptions(String url, HttpHeaders headers, Class<T> type) {
return getRestTemplate().exchange(prepareOptions(url, headers), type);
}
<T> ResponseEntity<T> performPost(String url, MediaType in, Object body, MediaType out, Class<T> type)
throws Exception {
<T> ResponseEntity<T> performPost(String url, MediaType in, Object body, MediaType out, Class<T> type) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(in);
if (out != null) {
@ -101,15 +95,11 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt @@ -101,15 +95,11 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt
return getRestTemplate().exchange(preparePost(url, headers, body), type);
}
<T> ResponseEntity<T> performPost(String url, HttpHeaders headers, Object body,
Class<T> type) throws Exception {
<T> ResponseEntity<T> performPost(String url, HttpHeaders headers, Object body, Class<T> type) {
return getRestTemplate().exchange(preparePost(url, headers, body), type);
}
<T> ResponseEntity<T> performPost(String url, MediaType in, Object body, MediaType out,
ParameterizedTypeReference<T> type) throws Exception {
<T> ResponseEntity<T> performPost(String url, MediaType in, Object body, MediaType out, ParameterizedTypeReference<T> type) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(in);
if (out != null) {
@ -118,15 +108,15 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt @@ -118,15 +108,15 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt
return getRestTemplate().exchange(preparePost(url, headers, body), type);
}
private RequestEntity<Void> prepareGet(String url, HttpHeaders headers) throws Exception {
URI uri = new URI("http://localhost:" + this.port + url);
private RequestEntity<Void> prepareGet(String url, HttpHeaders headers) {
URI uri = URI.create("http://localhost:" + this.port + url);
RequestEntity.HeadersBuilder<?> builder = RequestEntity.get(uri);
addHeaders(builder, headers);
return builder.build();
}
private RequestEntity<Void> prepareOptions(String url, HttpHeaders headers) throws Exception {
URI uri = new URI("http://localhost:" + this.port + url);
private RequestEntity<Void> prepareOptions(String url, HttpHeaders headers) {
URI uri = URI.create("http://localhost:" + this.port + url);
RequestEntity.HeadersBuilder<?> builder = RequestEntity.options(uri);
addHeaders(builder, headers);
return builder.build();
@ -140,8 +130,8 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt @@ -140,8 +130,8 @@ public abstract class AbstractRequestMappingIntegrationTests extends AbstractHtt
}
}
private RequestEntity<?> preparePost(String url, HttpHeaders headers, Object body) throws Exception {
URI uri = new URI("http://localhost:" + this.port + url);
private RequestEntity<?> preparePost(String url, HttpHeaders headers, Object body) {
URI uri = URI.create("http://localhost:" + this.port + url);
RequestEntity.BodyBuilder builder = RequestEntity.post(uri);
addHeaders(builder, headers);
return builder.body(body);

7
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ControllerInputIntegrationTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 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,10 +45,7 @@ class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationT @@ -45,10 +45,7 @@ class ControllerInputIntegrationTests extends AbstractRequestMappingIntegrationT
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class, TestRestController.class);
wac.refresh();
return wac;
return new AnnotationConfigApplicationContext(WebConfig.class, TestRestController.class);
}

9
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingViewResolutionIntegrationTests.java

@ -53,10 +53,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin @@ -53,10 +53,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin
@Override
protected ApplicationContext initApplicationContext() {
AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext();
wac.register(WebConfig.class);
wac.refresh();
return wac;
return new AnnotationConfigApplicationContext(WebConfig.class);
}
@ -72,7 +69,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin @@ -72,7 +69,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin
void etagCheckWithNotModifiedResponse(HttpServer httpServer) throws Exception {
startServer(httpServer);
URI uri = new URI("http://localhost:" + this.port + "/html");
URI uri = URI.create("http://localhost:" + this.port + "/html");
RequestEntity<Void> request = RequestEntity.get(uri).ifNoneMatch("\"deadb33f8badf00d\"").build();
ResponseEntity<String> response = getRestTemplate().exchange(request, String.class);
@ -92,7 +89,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin @@ -92,7 +89,7 @@ class RequestMappingViewResolutionIntegrationTests extends AbstractRequestMappin
}
};
URI uri = new URI("http://localhost:" + this.port + "/redirect");
URI uri = URI.create("http://localhost:" + this.port + "/redirect");
RequestEntity<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build();
@SuppressWarnings("resource")
ResponseEntity<Void> response = new RestTemplate(factory).exchange(request, Void.class);

83
spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandlerTests.java

@ -20,7 +20,6 @@ import java.net.URI; @@ -20,7 +20,6 @@ import java.net.URI;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
@ -32,7 +31,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; @@ -32,7 +31,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Single;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@ -54,7 +52,6 @@ import org.springframework.http.codec.ResourceHttpMessageWriter; @@ -54,7 +52,6 @@ import org.springframework.http.codec.ResourceHttpMessageWriter;
import org.springframework.http.codec.json.Jackson2JsonEncoder;
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.util.ObjectUtils;
import org.springframework.web.ErrorResponse;
import org.springframework.web.ErrorResponseException;
import org.springframework.web.reactive.HandlerResult;
@ -81,40 +78,28 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on; @@ -81,40 +78,28 @@ import static org.springframework.web.testfixture.method.ResolvableMethod.on;
* </ul>
* @author Rossen Stoyanchev
*/
public class ResponseEntityResultHandlerTests {
class ResponseEntityResultHandlerTests {
private static final String NEWLINE_SYSTEM_PROPERTY = System.lineSeparator();
private final ResponseEntityResultHandler resultHandler = createHandler();
private ResponseEntityResultHandler resultHandler;
@BeforeEach
public void setup() throws Exception {
this.resultHandler = createHandler();
}
private ResponseEntityResultHandler createHandler(HttpMessageWriter<?>... writers) {
List<HttpMessageWriter<?>> writerList;
if (ObjectUtils.isEmpty(writers)) {
writerList = new ArrayList<>();
writerList.add(new EncoderHttpMessageWriter<>(new ByteBufferEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()));
writerList.add(new ResourceHttpMessageWriter());
writerList.add(new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()));
writerList.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
}
else {
writerList = Arrays.asList(writers);
}
private static ResponseEntityResultHandler createHandler() {
List<HttpMessageWriter<?>> writerList = List.of(
new EncoderHttpMessageWriter<>(new ByteBufferEncoder()),
new EncoderHttpMessageWriter<>(CharSequenceEncoder.textPlainOnly()),
new ResourceHttpMessageWriter(),
new EncoderHttpMessageWriter<>(new Jaxb2XmlEncoder()),
new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder()),
new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
RequestedContentTypeResolver resolver = new RequestedContentTypeResolverBuilder().build();
return new ResponseEntityResultHandler(writerList, resolver);
}
@Test
public void supports() throws Exception {
void supports() {
Object value = null;
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
@ -145,7 +130,7 @@ public class ResponseEntityResultHandlerTests { @@ -145,7 +130,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void doesNotSupport() throws Exception {
void doesNotSupport() {
Object value = null;
MethodParameter returnType = on(TestController.class).resolveReturnType(String.class);
@ -160,12 +145,12 @@ public class ResponseEntityResultHandlerTests { @@ -160,12 +145,12 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void defaultOrder() throws Exception {
void defaultOrder() {
assertThat(this.resultHandler.getOrder()).isEqualTo(0);
}
@Test
public void responseEntityStatusCode() throws Exception {
void responseEntityStatusCode() {
ResponseEntity<Void> value = ResponseEntity.noContent().build();
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
HandlerResult result = handlerResult(value, returnType);
@ -178,7 +163,7 @@ public class ResponseEntityResultHandlerTests { @@ -178,7 +163,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void httpHeaders() throws Exception {
void httpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setAllow(new LinkedHashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST, HttpMethod.OPTIONS)));
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
@ -193,8 +178,8 @@ public class ResponseEntityResultHandlerTests { @@ -193,8 +178,8 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void responseEntityHeaders() throws Exception {
URI location = new URI("/path");
void responseEntityHeaders() {
URI location = URI.create("/path");
ResponseEntity<Void> value = ResponseEntity.created(location).build();
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
HandlerResult result = handlerResult(value, returnType);
@ -208,7 +193,7 @@ public class ResponseEntityResultHandlerTests { @@ -208,7 +193,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleResponseEntityWithNullBody() {
void handleResponseEntityWithNullBody() {
Object returnValue = Mono.just(notFound().build());
MethodParameter type = on(TestController.class).resolveReturnType(Mono.class, entity(String.class));
HandlerResult result = handlerResult(returnValue, type);
@ -220,7 +205,7 @@ public class ResponseEntityResultHandlerTests { @@ -220,7 +205,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleReturnTypes() {
void handleReturnTypes() {
Object returnValue = ResponseEntity.ok("abc");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
testHandle(returnValue, returnType);
@ -242,7 +227,7 @@ public class ResponseEntityResultHandlerTests { @@ -242,7 +227,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleErrorResponse() {
void handleErrorResponse() {
ErrorResponseException ex = new ErrorResponseException(HttpStatus.BAD_REQUEST);
ex.getHeaders().add("foo", "bar");
MethodParameter returnType = on(TestController.class).resolveReturnType(ErrorResponse.class);
@ -263,7 +248,7 @@ public class ResponseEntityResultHandlerTests { @@ -263,7 +248,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleProblemDetail() {
void handleProblemDetail() {
ProblemDetail problemDetail = ProblemDetail.forStatus(HttpStatus.BAD_REQUEST);
MethodParameter returnType = on(TestController.class).resolveReturnType(ProblemDetail.class);
HandlerResult result = handlerResult(problemDetail, returnType);
@ -282,7 +267,7 @@ public class ResponseEntityResultHandlerTests { @@ -282,7 +267,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleReturnValueLastModified() throws Exception {
void handleReturnValueLastModified() {
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
Instant oneMinAgo = currentTime.minusSeconds(60);
long timestamp = currentTime.toEpochMilli();
@ -297,7 +282,7 @@ public class ResponseEntityResultHandlerTests { @@ -297,7 +282,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleReturnValueEtag() throws Exception {
void handleReturnValueEtag() {
String etagValue = "\"deadb33f8badf00d\"";
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch(etagValue));
@ -310,7 +295,7 @@ public class ResponseEntityResultHandlerTests { @@ -310,7 +295,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // SPR-14559
public void handleReturnValueEtagInvalidIfNoneMatch() throws Exception {
void handleReturnValueEtagInvalidIfNoneMatch() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path").ifNoneMatch("unquoted"));
ResponseEntity<String> entity = ResponseEntity.ok().eTag("\"deadb33f8badf00d\"").body("body");
@ -323,7 +308,7 @@ public class ResponseEntityResultHandlerTests { @@ -323,7 +308,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleReturnValueETagAndLastModified() throws Exception {
void handleReturnValueETagAndLastModified() {
String eTag = "\"deadb33f8badf00d\"";
Instant currentTime = Instant.now().truncatedTo(ChronoUnit.SECONDS);
@ -343,7 +328,7 @@ public class ResponseEntityResultHandlerTests { @@ -343,7 +328,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test
public void handleReturnValueChangedETagAndLastModified() throws Exception {
void handleReturnValueChangedETagAndLastModified() {
String etag = "\"deadb33f8badf00d\"";
String newEtag = "\"changed-etag-value\"";
@ -364,7 +349,7 @@ public class ResponseEntityResultHandlerTests { @@ -364,7 +349,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // SPR-14877
public void handleMonoWithWildcardBodyType() throws Exception {
void handleMonoWithWildcardBodyType() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
@ -378,7 +363,7 @@ public class ResponseEntityResultHandlerTests { @@ -378,7 +363,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // SPR-14877
public void handleMonoWithWildcardBodyTypeAndNullBody() throws Exception {
void handleMonoWithWildcardBodyTypeAndNullBody() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/path"));
exchange.getAttributes().put(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE, Collections.singleton(APPLICATION_JSON));
@ -392,7 +377,7 @@ public class ResponseEntityResultHandlerTests { @@ -392,7 +377,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // SPR-17082
public void handleWithPresetContentType() {
void handleWithPresetContentType() {
ResponseEntity<Void> value = ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).build();
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(Void.class));
HandlerResult result = handlerResult(value, returnType);
@ -407,7 +392,7 @@ public class ResponseEntityResultHandlerTests { @@ -407,7 +392,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // gh-23205
public void handleWithPresetContentTypeShouldFailWithServerError() {
void handleWithPresetContentTypeShouldFailWithServerError() {
ResponseEntity<String> value = ResponseEntity.ok().contentType(MediaType.APPLICATION_XML).body("<foo/>");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(value, returnType);
@ -426,7 +411,7 @@ public class ResponseEntityResultHandlerTests { @@ -426,7 +411,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // gh-23287
public void handleWithProducibleContentTypeShouldFailWithServerError() {
void handleWithProducibleContentTypeShouldFailWithServerError() {
ResponseEntity<String> value = ResponseEntity.ok().body("<foo/>");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(value, returnType);
@ -448,7 +433,7 @@ public class ResponseEntityResultHandlerTests { @@ -448,7 +433,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // gh-26212
public void handleWithObjectMapperByTypeRegistration() {
void handleWithObjectMapperByTypeRegistration() {
MediaType halFormsMediaType = MediaType.parseMediaType("application/prs.hal-forms+json");
MediaType halMediaType = MediaType.parseMediaType("application/hal+json");
@ -479,7 +464,7 @@ public class ResponseEntityResultHandlerTests { @@ -479,7 +464,7 @@ public class ResponseEntityResultHandlerTests {
}
@Test // gh-24539
public void malformedAcceptHeader() {
void malformedAcceptHeader() {
ResponseEntity<String> value = ResponseEntity.badRequest().body("Foo");
MethodParameter returnType = on(TestController.class).resolveReturnType(entity(String.class));
HandlerResult result = handlerResult(value, returnType);
@ -525,7 +510,7 @@ public class ResponseEntityResultHandlerTests { @@ -525,7 +510,7 @@ public class ResponseEntityResultHandlerTests {
}
private void assertConditionalResponse(MockServerWebExchange exchange, HttpStatus status,
String body, String etag, Instant lastModified) throws Exception {
String body, String etag, Instant lastModified) {
assertThat(exchange.getResponse().getStatusCode()).isEqualTo(status);
if (body != null) {

Loading…
Cancel
Save