Suppress deprecation warnings in tests

This commit is contained in:
Sam Brannen
2022-03-29 15:04:58 +02:00
parent c8d0146bcc
commit 7a1421cb0f
12 changed files with 217 additions and 213 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -31,10 +31,10 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Marcel Overdijk
* @author Kazuki Shimizu
*/
public class ResponseEntityTests {
class ResponseEntityTests {
@Test
public void normal() {
void normal() {
String headerName = "My-Custom-Header";
String headerValue1 = "HeaderValue1";
String headerValue2 = "HeaderValue2";
@@ -54,7 +54,7 @@ public class ResponseEntityTests {
}
@Test
public void okNoBody() {
void okNoBody() {
ResponseEntity<Void> responseEntity = ResponseEntity.ok().build();
assertThat(responseEntity).isNotNull();
@@ -63,7 +63,7 @@ public class ResponseEntityTests {
}
@Test
public void okEntity() {
void okEntity() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.ok(entity);
@@ -73,7 +73,7 @@ public class ResponseEntityTests {
}
@Test
public void ofOptional() {
void ofOptional() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.of(Optional.of(entity));
@@ -83,7 +83,7 @@ public class ResponseEntityTests {
}
@Test
public void ofEmptyOptional() {
void ofEmptyOptional() {
ResponseEntity<Integer> responseEntity = ResponseEntity.of(Optional.empty());
assertThat(responseEntity).isNotNull();
@@ -92,7 +92,7 @@ public class ResponseEntityTests {
}
@Test
public void createdLocation() throws URISyntaxException {
void createdLocation() throws URISyntaxException {
URI location = new URI("location");
ResponseEntity<Void> responseEntity = ResponseEntity.created(location).build();
@@ -106,7 +106,7 @@ public class ResponseEntityTests {
}
@Test
public void acceptedNoBody() throws URISyntaxException {
void acceptedNoBody() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.accepted().build();
assertThat(responseEntity).isNotNull();
@@ -115,7 +115,7 @@ public class ResponseEntityTests {
}
@Test // SPR-14939
public void acceptedNoBodyWithAlternativeBodyType() throws URISyntaxException {
void acceptedNoBodyWithAlternativeBodyType() throws URISyntaxException {
ResponseEntity<String> responseEntity = ResponseEntity.accepted().build();
assertThat(responseEntity).isNotNull();
@@ -124,7 +124,7 @@ public class ResponseEntityTests {
}
@Test
public void noContent() throws URISyntaxException {
void noContent() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.noContent().build();
assertThat(responseEntity).isNotNull();
@@ -133,7 +133,7 @@ public class ResponseEntityTests {
}
@Test
public void badRequest() throws URISyntaxException {
void badRequest() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.badRequest().build();
assertThat(responseEntity).isNotNull();
@@ -142,7 +142,7 @@ public class ResponseEntityTests {
}
@Test
public void notFound() throws URISyntaxException {
void notFound() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.notFound().build();
assertThat(responseEntity).isNotNull();
@@ -151,7 +151,7 @@ public class ResponseEntityTests {
}
@Test
public void unprocessableEntity() throws URISyntaxException {
void unprocessableEntity() throws URISyntaxException {
ResponseEntity<String> responseEntity = ResponseEntity.unprocessableEntity().body("error");
assertThat(responseEntity).isNotNull();
@@ -160,7 +160,7 @@ public class ResponseEntityTests {
}
@Test
public void internalServerError() throws URISyntaxException {
void internalServerError() throws URISyntaxException {
ResponseEntity<String> responseEntity = ResponseEntity.internalServerError().body("error");
assertThat(responseEntity).isNotNull();
@@ -169,7 +169,7 @@ public class ResponseEntityTests {
}
@Test
public void headers() throws URISyntaxException {
void headers() throws URISyntaxException {
URI location = new URI("location");
long contentLength = 67890;
MediaType contentType = MediaType.TEXT_PLAIN;
@@ -197,7 +197,7 @@ public class ResponseEntityTests {
}
@Test
public void Etagheader() throws URISyntaxException {
void Etagheader() throws URISyntaxException {
ResponseEntity<Void> responseEntity = ResponseEntity.ok().eTag("\"foo\"").build();
assertThat(responseEntity.getHeaders().getETag()).isEqualTo("\"foo\"");
@@ -210,7 +210,7 @@ public class ResponseEntityTests {
}
@Test
public void headersCopy() {
void headersCopy() {
HttpHeaders customHeaders = new HttpHeaders();
customHeaders.set("X-CustomHeader", "vale");
@@ -225,7 +225,7 @@ public class ResponseEntityTests {
}
@Test // SPR-12792
public void headersCopyWithEmptyAndNull() {
void headersCopyWithEmptyAndNull() {
ResponseEntity<Void> responseEntityWithEmptyHeaders =
ResponseEntity.ok().headers(new HttpHeaders()).build();
ResponseEntity<Void> responseEntityWithNullHeaders =
@@ -237,7 +237,7 @@ public class ResponseEntityTests {
}
@Test
public void emptyCacheControl() {
void emptyCacheControl() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
@@ -252,7 +252,7 @@ public class ResponseEntityTests {
}
@Test
public void cacheControl() {
void cacheControl() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
@@ -271,7 +271,7 @@ public class ResponseEntityTests {
}
@Test
public void cacheControlNoCache() {
void cacheControlNoCache() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity =
@@ -289,7 +289,7 @@ public class ResponseEntityTests {
}
@Test
public void statusCodeAsInt() {
void statusCodeAsInt() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.status(200).body(entity);
@@ -298,7 +298,8 @@ public class ResponseEntityTests {
}
@Test
public void customStatusCode() {
@SuppressWarnings("deprecation")
void customStatusCode() {
Integer entity = 42;
ResponseEntity<Integer> responseEntity = ResponseEntity.status(299).body(entity);

View File

@@ -40,7 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Arjen Poutsma
* @author Juergen Hoeller
*/
public class InterceptingClientHttpRequestFactoryTests {
class InterceptingClientHttpRequestFactoryTests {
private RequestFactoryMock requestFactoryMock = new RequestFactoryMock();
@@ -52,7 +52,7 @@ public class InterceptingClientHttpRequestFactoryTests {
@Test
public void basic() throws Exception {
void basic() throws Exception {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new NoOpInterceptor());
interceptors.add(new NoOpInterceptor());
@@ -70,7 +70,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Test
public void noExecution() throws Exception {
void noExecution() throws Exception {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add((request, body, execution) -> responseMock);
@@ -86,7 +86,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Test
public void changeHeaders() throws Exception {
void changeHeaders() throws Exception {
final String headerName = "Foo";
final String headerValue = "Bar";
final String otherValue = "Baz";
@@ -116,7 +116,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Test
public void changeURI() throws Exception {
void changeURI() throws Exception {
final URI changedUri = new URI("https://example.com/2");
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(new HttpRequestWrapper(request) {
@@ -142,7 +142,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Test
public void changeMethod() throws Exception {
void changeMethod() throws Exception {
final HttpMethod changedMethod = HttpMethod.POST;
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(new HttpRequestWrapper(request) {
@@ -168,7 +168,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Test
public void changeBody() throws Exception {
void changeBody() throws Exception {
final byte[] changedBody = "Foo".getBytes();
ClientHttpRequestInterceptor interceptor = (request, body, execution) -> execution.execute(request, changedBody);
@@ -277,6 +277,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Override
@SuppressWarnings("deprecation")
public int getRawStatusCode() throws IOException {
return statusCode.value();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 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.
@@ -756,6 +756,7 @@ class RestTemplateTests {
given(request.getHeaders()).willReturn(requestHeaders);
}
@SuppressWarnings("deprecation")
private void mockResponseStatus(HttpStatus responseStatus) throws Exception {
given(request.execute()).willReturn(response);
given(errorHandler.hasError(response)).willReturn(responseStatus.isError());

View File

@@ -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.
@@ -38,10 +38,10 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
*/
public class DefaultClientResponseBuilderTests {
class DefaultClientResponseBuilderTests {
@Test
public void normal() {
void normal() {
Flux<DataBuffer> body = Flux.just("baz")
.map(s -> s.getBytes(StandardCharsets.UTF_8))
.map(DefaultDataBufferFactory.sharedInstance::wrap);
@@ -64,7 +64,7 @@ public class DefaultClientResponseBuilderTests {
}
@Test
public void mutate() {
void mutate() {
Flux<DataBuffer> otherBody = Flux.just("foo", "bar")
.map(s -> s.getBytes(StandardCharsets.UTF_8))
.map(DefaultDataBufferFactory.sharedInstance::wrap);
@@ -101,11 +101,13 @@ public class DefaultClientResponseBuilderTests {
}
@Test
public void mutateWithCustomStatus() {
@SuppressWarnings("deprecation")
void mutateWithCustomStatus() {
ClientResponse other = ClientResponse.create(499, ExchangeStrategies.withDefaults()).build();
ClientResponse result = other.mutate().build();
assertThat(result.rawStatusCode()).isEqualTo(499);
assertThat(result.statusCode()).isEqualTo(HttpStatusCode.valueOf(499));
}
}

View File

@@ -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.
@@ -59,7 +59,7 @@ import static org.springframework.web.reactive.function.BodyExtractors.toMono;
* @author Arjen Poutsma
* @author Denys Ivano
*/
public class DefaultClientResponseTests {
class DefaultClientResponseTests {
private ClientHttpResponse mockResponse;
@@ -71,7 +71,7 @@ public class DefaultClientResponseTests {
@BeforeEach
public void createMocks() {
void createMocks() {
mockResponse = mock(ClientHttpResponse.class);
given(mockResponse.getHeaders()).willReturn(this.httpHeaders);
mockExchangeStrategies = mock(ExchangeStrategies.class);
@@ -80,7 +80,7 @@ public class DefaultClientResponseTests {
@Test
public void statusCode() {
void statusCode() {
HttpStatus status = HttpStatus.CONTINUE;
given(mockResponse.getStatusCode()).willReturn(status);
@@ -88,7 +88,8 @@ public class DefaultClientResponseTests {
}
@Test
public void rawStatusCode() {
@SuppressWarnings("deprecation")
void rawStatusCode() {
int status = 999;
given(mockResponse.getRawStatusCode()).willReturn(status);
@@ -96,7 +97,7 @@ public class DefaultClientResponseTests {
}
@Test
public void header() {
void header() {
long contentLength = 42L;
httpHeaders.setContentLength(contentLength);
MediaType contentType = MediaType.TEXT_PLAIN;
@@ -115,7 +116,7 @@ public class DefaultClientResponseTests {
}
@Test
public void cookies() {
void cookies() {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
MultiValueMap<String, ResponseCookie> cookies = new LinkedMultiValueMap<>();
cookies.add("foo", cookie);
@@ -127,7 +128,7 @@ public class DefaultClientResponseTests {
@Test
public void body() {
void body() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -142,7 +143,7 @@ public class DefaultClientResponseTests {
}
@Test
public void bodyToMono() {
void bodyToMono() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -157,7 +158,7 @@ public class DefaultClientResponseTests {
}
@Test
public void bodyToMonoTypeReference() {
void bodyToMonoTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -174,7 +175,7 @@ public class DefaultClientResponseTests {
}
@Test
public void bodyToFlux() {
void bodyToFlux() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -190,7 +191,7 @@ public class DefaultClientResponseTests {
}
@Test
public void bodyToFluxTypeReference() {
void bodyToFluxTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -208,7 +209,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntity() {
@SuppressWarnings("deprecation")
void toEntity() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -226,7 +228,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntityWithUnknownStatusCode() throws Exception {
@SuppressWarnings("deprecation")
void toEntityWithUnknownStatusCode() throws Exception {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -248,7 +251,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntityTypeReference() {
@SuppressWarnings("deprecation")
void toEntityTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -268,7 +272,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntityList() {
@SuppressWarnings("deprecation")
void toEntityList() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -286,7 +291,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntityListWithUnknownStatusCode() {
@SuppressWarnings("deprecation")
void toEntityListWithUnknownStatusCode() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -308,7 +314,8 @@ public class DefaultClientResponseTests {
}
@Test
public void toEntityListTypeReference() {
@SuppressWarnings("deprecation")
void toEntityListTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -328,7 +335,8 @@ public class DefaultClientResponseTests {
}
@Test
public void createException() {
@SuppressWarnings("deprecation")
void createException() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -351,7 +359,8 @@ public class DefaultClientResponseTests {
}
@Test
public void createError() {
@SuppressWarnings("deprecation")
void createError() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
@@ -380,6 +389,7 @@ public class DefaultClientResponseTests {
}
@SuppressWarnings("deprecation")
private void mockTextPlainResponse(Flux<DataBuffer> body) {
httpHeaders.setContentType(MediaType.TEXT_PLAIN);
given(mockResponse.getStatusCode()).willReturn(HttpStatus.OK);

View File

@@ -529,6 +529,7 @@ class WebClientIntegrationTests {
}
@ParameterizedWebClientTest
@SuppressWarnings("deprecation")
void retrieve500(ClientHttpConnector connector) {
startServer(connector);
@@ -544,7 +545,7 @@ class WebClientIntegrationTests {
StepVerifier.create(result)
.expectErrorSatisfies(throwable -> {
assertThat(throwable instanceof WebClientResponseException).isTrue();
assertThat(throwable).isInstanceOf(WebClientResponseException.class);
WebClientResponseException ex = (WebClientResponseException) throwable;
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(ex.getRawStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.value());
@@ -636,11 +637,12 @@ class WebClientIntegrationTests {
}
@ParameterizedWebClientTest
@SuppressWarnings("deprecation")
void retrieve555UnknownStatus(ClientHttpConnector connector) {
startServer(connector);
int errorStatus = 555;
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
assertThat(HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
prepareResponse(response -> response.setResponseCode(errorStatus)
.setHeader("Content-Type", "text/plain").setBody(errorMessage));
@@ -652,7 +654,7 @@ class WebClientIntegrationTests {
StepVerifier.create(result)
.expectErrorSatisfies(throwable -> {
assertThat(throwable instanceof UnknownHttpStatusCodeException).isTrue();
assertThat(throwable).isInstanceOf(UnknownHttpStatusCodeException.class);
UnknownHttpStatusCodeException ex = (UnknownHttpStatusCodeException) throwable;
assertThat(ex.getMessage()).isEqualTo(("Unknown status code ["+errorStatus+"]"));
assertThat(ex.getRawStatusCode()).isEqualTo(errorStatus);
@@ -1055,11 +1057,12 @@ class WebClientIntegrationTests {
}
@ParameterizedWebClientTest
@SuppressWarnings("deprecation")
void exchangeForUnknownStatusCode(ClientHttpConnector connector) {
startServer(connector);
int errorStatus = 555;
assertThat((Object) HttpStatus.resolve(errorStatus)).isNull();
assertThat(HttpStatus.resolve(errorStatus)).isNull();
String errorMessage = "Something went wrong";
prepareResponse(response -> response.setResponseCode(errorStatus)
.setHeader("Content-Type", "text/plain").setBody(errorMessage));

View File

@@ -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.
@@ -18,7 +18,6 @@ package org.springframework.web.reactive.function.client.support;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -41,25 +40,20 @@ import static org.mockito.Mockito.mock;
/**
* @author Arjen Poutsma
*/
public class ClientResponseWrapperTests {
class ClientResponseWrapperTests {
private ClientResponse mockResponse;
private ClientResponse mockResponse = mock(ClientResponse.class);
private ClientResponseWrapper wrapper;
private ClientResponseWrapper wrapper = new ClientResponseWrapper(mockResponse);
@BeforeEach
public void createWrapper() {
this.mockResponse = mock(ClientResponse.class);
this.wrapper = new ClientResponseWrapper(mockResponse);
}
@Test
public void response() {
void response() {
assertThat(wrapper.response()).isSameAs(mockResponse);
}
@Test
public void statusCode() {
void statusCode() {
HttpStatus status = HttpStatus.BAD_REQUEST;
given(mockResponse.statusCode()).willReturn(status);
@@ -67,7 +61,8 @@ public class ClientResponseWrapperTests {
}
@Test
public void rawStatusCode() {
@SuppressWarnings("deprecation")
void rawStatusCode() {
int status = 999;
given(mockResponse.rawStatusCode()).willReturn(status);
@@ -75,7 +70,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void headers() {
void headers() {
ClientResponse.Headers headers = mock(ClientResponse.Headers.class);
given(mockResponse.headers()).willReturn(headers);
@@ -84,7 +79,7 @@ public class ClientResponseWrapperTests {
@Test
@SuppressWarnings("unchecked")
public void cookies() {
void cookies() {
MultiValueMap<String, ResponseCookie> cookies = mock(MultiValueMap.class);
given(mockResponse.cookies()).willReturn(cookies);
@@ -92,7 +87,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void bodyExtractor() {
void bodyExtractor() {
Mono<String> result = Mono.just("foo");
BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
given(mockResponse.body(extractor)).willReturn(result);
@@ -101,7 +96,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void bodyToMonoClass() {
void bodyToMonoClass() {
Mono<String> result = Mono.just("foo");
given(mockResponse.bodyToMono(String.class)).willReturn(result);
@@ -109,7 +104,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void bodyToMonoParameterizedTypeReference() {
void bodyToMonoParameterizedTypeReference() {
Mono<String> result = Mono.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.bodyToMono(reference)).willReturn(result);
@@ -118,7 +113,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void bodyToFluxClass() {
void bodyToFluxClass() {
Flux<String> result = Flux.just("foo");
given(mockResponse.bodyToFlux(String.class)).willReturn(result);
@@ -126,7 +121,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void bodyToFluxParameterizedTypeReference() {
void bodyToFluxParameterizedTypeReference() {
Flux<String> result = Flux.just("foo");
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.bodyToFlux(reference)).willReturn(result);
@@ -135,7 +130,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void toEntityClass() {
void toEntityClass() {
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
given(mockResponse.toEntity(String.class)).willReturn(result);
@@ -143,7 +138,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void toEntityParameterizedTypeReference() {
void toEntityParameterizedTypeReference() {
Mono<ResponseEntity<String>> result = Mono.just(new ResponseEntity<>("foo", HttpStatus.OK));
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.toEntity(reference)).willReturn(result);
@@ -152,7 +147,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void toEntityListClass() {
void toEntityListClass() {
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
given(mockResponse.toEntityList(String.class)).willReturn(result);
@@ -160,7 +155,7 @@ public class ClientResponseWrapperTests {
}
@Test
public void toEntityListParameterizedTypeReference() {
void toEntityListParameterizedTypeReference() {
Mono<ResponseEntity<List<String>>> result = Mono.just(new ResponseEntity<>(singletonList("foo"), HttpStatus.OK));
ParameterizedTypeReference<String> reference = new ParameterizedTypeReference<>() {};
given(mockResponse.toEntityList(reference)).willReturn(result);

View File

@@ -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.
@@ -52,24 +52,24 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
*/
public class DefaultEntityResponseBuilderTests {
class DefaultEntityResponseBuilderTests {
@Test
public void fromObject() {
void fromObject() {
String body = "foo";
EntityResponse<String> response = EntityResponse.fromObject(body).build().block();
assertThat(response.entity()).isSameAs(body);
}
@Test
public void fromPublisherClass() {
void fromPublisherClass() {
Flux<String> body = Flux.just("foo", "bar");
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, String.class).build().block();
assertThat(response.entity()).isSameAs(body);
}
@Test
public void fromPublisher() {
void fromPublisher() {
Flux<String> body = Flux.just("foo", "bar");
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
EntityResponse<Flux<String>> response = EntityResponse.fromPublisher(body, typeReference).build().block();
@@ -77,7 +77,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void fromProducer() {
void fromProducer() {
Single<String> body = Single.just("foo");
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
EntityResponse<Single<String>> response = EntityResponse.fromProducer(body, typeReference).build().block();
@@ -85,7 +85,8 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void status() {
@SuppressWarnings("deprecation")
void status() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).status(HttpStatus.CREATED).build();
StepVerifier.create(result)
@@ -96,7 +97,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void allow() {
void allow() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).allow(HttpMethod.GET).build();
Set<HttpMethod> expected = Set.of(HttpMethod.GET);
@@ -107,7 +108,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void contentLength() {
void contentLength() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).contentLength(42).build();
StepVerifier.create(result)
@@ -117,7 +118,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void contentType() {
void contentType() {
String body = "foo";
Mono<EntityResponse<String>>
result = EntityResponse.fromObject(body).contentType(MediaType.APPLICATION_JSON).build();
@@ -128,7 +129,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void etag() {
void etag() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).eTag("foo").build();
StepVerifier.create(result)
@@ -138,7 +139,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void lastModified() {
void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).lastModified(now).build();
@@ -150,7 +151,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void cacheControlTag() {
void cacheControlTag() {
String body = "foo";
Mono<EntityResponse<String>>
result = EntityResponse.fromObject(body).cacheControl(CacheControl.noCache()).build();
@@ -161,7 +162,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void varyBy() {
void varyBy() {
String body = "foo";
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).varyBy("foo").build();
List<String> expected = Collections.singletonList("foo");
@@ -172,7 +173,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void headers() {
void headers() {
String body = "foo";
HttpHeaders headers = new HttpHeaders();
Mono<EntityResponse<String>> result = EntityResponse.fromObject(body).headers(headers).build();
@@ -183,7 +184,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void cookies() {
void cookies() {
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
newCookies.add("name", ResponseCookie.from("name", "value").build());
Mono<EntityResponse<String>> result =
@@ -195,7 +196,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void bodyInserter() {
void bodyInserter() {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
@@ -229,7 +230,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void notModifiedEtag() {
void notModifiedEtag() {
String etag = "\"foo\"";
EntityResponse<String> responseMono = EntityResponse.fromObject("bar")
.eTag(etag)
@@ -251,7 +252,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void notModifiedLastModified() {
void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);

View File

@@ -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.
@@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
/**
* @author Arjen Poutsma
*/
public class DefaultServerResponseBuilderTests {
class DefaultServerResponseBuilderTests {
static final ServerResponse.Context EMPTY_CONTEXT = new ServerResponse.Context() {
@Override
@@ -64,7 +64,7 @@ public class DefaultServerResponseBuilderTests {
@Test
public void from() {
void from() {
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
ServerResponse other = ServerResponse.ok().header("foo", "bar")
.cookie(cookie)
@@ -81,7 +81,8 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void status() {
@SuppressWarnings("deprecation")
void status() {
Mono<ServerResponse> result = ServerResponse.status(HttpStatus.CREATED).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.CREATED.equals(response.statusCode()) &&
@@ -91,17 +92,16 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void ok() {
void ok() {
Mono<ServerResponse> result = ServerResponse.ok().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.OK.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void created() {
void created() {
URI location = URI.create("https://example.com");
Mono<ServerResponse> result = ServerResponse.created(location).build();
StepVerifier.create(result)
@@ -112,27 +112,25 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void accepted() {
void accepted() {
Mono<ServerResponse> result = ServerResponse.accepted().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.ACCEPTED.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void noContent() {
void noContent() {
Mono<ServerResponse> result = ServerResponse.noContent().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.NO_CONTENT.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void seeOther() {
void seeOther() {
URI location = URI.create("https://example.com");
Mono<ServerResponse> result = ServerResponse.seeOther(location).build();
StepVerifier.create(result)
@@ -143,7 +141,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void temporaryRedirect() {
void temporaryRedirect() {
URI location = URI.create("https://example.com");
Mono<ServerResponse> result = ServerResponse.temporaryRedirect(location).build();
StepVerifier.create(result)
@@ -154,7 +152,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void permanentRedirect() {
void permanentRedirect() {
URI location = URI.create("https://example.com");
Mono<ServerResponse> result = ServerResponse.permanentRedirect(location).build();
StepVerifier.create(result)
@@ -165,58 +163,53 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void badRequest() {
void badRequest() {
Mono<ServerResponse> result = ServerResponse.badRequest().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.BAD_REQUEST.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void notFound() {
void notFound() {
Mono<ServerResponse> result = ServerResponse.notFound().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.NOT_FOUND.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void unprocessableEntity() {
void unprocessableEntity() {
Mono<ServerResponse> result = ServerResponse.unprocessableEntity().build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.UNPROCESSABLE_ENTITY.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void allow() {
void allow() {
Mono<ServerResponse> result = ServerResponse.ok().allow(HttpMethod.GET).build();
Set<HttpMethod> expected = Set.of(HttpMethod.GET);
StepVerifier.create(result)
.expectNextMatches(response -> expected.equals(response.headers().getAllow()))
.expectComplete()
.verify();
}
@Test
public void contentLength() {
void contentLength() {
Mono<ServerResponse> result = ServerResponse.ok().contentLength(42).build();
StepVerifier.create(result)
.expectNextMatches(response -> Long.valueOf(42).equals(response.headers().getContentLength()))
.expectComplete()
.verify();
}
@Test
public void contentType() {
void contentType() {
Mono<ServerResponse>
result = ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build();
StepVerifier.create(result)
@@ -226,17 +219,16 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void eTag() {
void eTag() {
Mono<ServerResponse> result = ServerResponse.ok().eTag("foo").build();
StepVerifier.create(result)
.expectNextMatches(response -> "\"foo\"".equals(response.headers().getETag()))
.expectComplete()
.verify();
}
@Test
public void lastModified() {
void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
Mono<ServerResponse> result = ServerResponse.ok().lastModified(now).build();
Long expected = now.toInstant().toEpochMilli() / 1000;
@@ -247,7 +239,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void cacheControlTag() {
void cacheControlTag() {
Mono<ServerResponse>
result = ServerResponse.ok().cacheControl(CacheControl.noCache()).build();
StepVerifier.create(result)
@@ -257,29 +249,27 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void varyBy() {
void varyBy() {
Mono<ServerResponse> result = ServerResponse.ok().varyBy("foo").build();
List<String> expected = Collections.singletonList("foo");
StepVerifier.create(result)
.expectNextMatches(response -> expected.equals(response.headers().getVary()))
.expectComplete()
.verify();
}
@Test
public void statusCode() {
void statusCode() {
HttpStatus statusCode = HttpStatus.ACCEPTED;
Mono<ServerResponse> result = ServerResponse.status(statusCode).build();
StepVerifier.create(result)
.expectNextMatches(response -> statusCode.equals(response.statusCode()))
.expectComplete()
.verify();
}
@Test
public void headers() {
void headers() {
HttpHeaders newHeaders = new HttpHeaders();
newHeaders.set("foo", "bar");
Mono<ServerResponse> result =
@@ -288,11 +278,10 @@ public class DefaultServerResponseBuilderTests {
.expectNextMatches(response -> newHeaders.equals(response.headers()))
.expectComplete()
.verify();
}
@Test
public void cookies() {
void cookies() {
MultiValueMap<String, ResponseCookie> newCookies = new LinkedMultiValueMap<>();
newCookies.add("name", ResponseCookie.from("name", "value").build());
Mono<ServerResponse> result =
@@ -304,7 +293,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void copyCookies() {
void copyCookies() {
Mono<ServerResponse> serverResponse = ServerResponse.ok()
.cookie(ResponseCookie.from("foo", "bar").build())
.bodyValue("body");
@@ -315,12 +304,11 @@ public class DefaultServerResponseBuilderTests {
.cookie(ResponseCookie.from("foo", "bar").build())
.bodyValue("body");
assertThat(serverResponse.block().cookies().isEmpty()).isFalse();
}
@Test
public void overwriteHeaders() {
void overwriteHeaders() {
ServerResponse serverResponse =
ServerResponse.ok().headers(headers -> headers.set("Foo", "Bar")).build().block();
assertThat(serverResponse).isNotNull();
@@ -338,7 +326,7 @@ public class DefaultServerResponseBuilderTests {
@Test
public void build() {
void build() {
ResponseCookie cookie = ResponseCookie.from("name", "value").build();
Mono<ServerResponse>
result = ServerResponse.status(HttpStatus.CREATED)
@@ -358,7 +346,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void buildVoidPublisher() {
void buildVoidPublisher() {
Mono<Void> mono = Mono.empty();
Mono<ServerResponse> result = ServerResponse.ok().build(mono);
@@ -372,7 +360,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void bodyObjectPublisher() {
void bodyObjectPublisher() {
Mono<Void> mono = Mono.empty();
assertThatIllegalArgumentException().isThrownBy(() ->
@@ -380,7 +368,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void notModifiedEtag() {
void notModifiedEtag() {
String etag = "\"foo\"";
ServerResponse responseMono = ServerResponse.ok()
.eTag(etag)
@@ -402,7 +390,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void notModifiedLastModified() {
void notModifiedLastModified() {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);

View File

@@ -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.
@@ -48,10 +48,10 @@ import static org.mockito.Mockito.mock;
* @author Arjen Poutsma
* @since 5.0
*/
public class RouterFunctionsTests {
class RouterFunctionsTests {
@Test
public void routeMatch() {
void routeMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
@@ -72,7 +72,7 @@ public class RouterFunctionsTests {
}
@Test
public void routeNoMatch() {
void routeNoMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
MockServerHttpRequest mockRequest = MockServerHttpRequest.get("https://example.com").build();
@@ -90,7 +90,7 @@ public class RouterFunctionsTests {
}
@Test
public void nestMatch() {
void nestMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Mono.just(handlerFunction);
@@ -110,7 +110,7 @@ public class RouterFunctionsTests {
}
@Test
public void nestNoMatch() {
void nestNoMatch() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().build();
RouterFunction<ServerResponse> routerFunction = request -> Mono.just(handlerFunction);
@@ -129,7 +129,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerNormal() {
void toHttpHandlerNormal() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
RouterFunction<ServerResponse> routerFunction =
RouterFunctions.route(RequestPredicates.all(), handlerFunction);
@@ -144,7 +144,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerHandlerThrowsException() {
void toHttpHandlerHandlerThrowsException() {
HandlerFunction<ServerResponse> handlerFunction =
request -> {
throw new IllegalStateException();
@@ -162,7 +162,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerHandlerReturnsException() {
void toHttpHandlerHandlerReturnsException() {
HandlerFunction<ServerResponse> handlerFunction =
request -> Mono.error(new IllegalStateException());
RouterFunction<ServerResponse> routerFunction =
@@ -178,7 +178,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerHandlerResponseStatusException() {
void toHttpHandlerHandlerResponseStatusException() {
HandlerFunction<ServerResponse> handlerFunction =
request -> Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found"));
RouterFunction<ServerResponse> routerFunction =
@@ -194,7 +194,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerRouteNotFoundReturnsResponseStatusException() {
void toHttpHandlerRouteNotFoundReturnsResponseStatusException() {
HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.accepted().build();
RouterFunction<ServerResponse> routerFunction =
RouterFunctions.route(RequestPredicates.GET("/path"), handlerFunction);
@@ -215,7 +215,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() {
void toHttpHandlerHandlerReturnResponseStatusExceptionInResponseWriteTo() {
HandlerFunction<ServerResponse> handlerFunction =
// Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.just(new ServerResponse() {
@@ -223,6 +223,7 @@ public class RouterFunctionsTests {
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@SuppressWarnings("deprecation")
@Override
public int rawStatusCode() {
return 200;
@@ -253,7 +254,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() {
void toHttpHandlerHandlerThrowResponseStatusExceptionInResponseWriteTo() {
HandlerFunction<ServerResponse> handlerFunction =
// Mono.<ServerResponse> is required for compilation in Eclipse
request -> Mono.just(new ServerResponse() {
@@ -261,6 +262,7 @@ public class RouterFunctionsTests {
public HttpStatus statusCode() {
return HttpStatus.OK;
}
@SuppressWarnings("deprecation")
@Override
public int rawStatusCode() {
return 200;
@@ -291,7 +293,7 @@ public class RouterFunctionsTests {
}
@Test
public void toHttpHandlerWebFilter() {
void toHttpHandlerWebFilter() {
AtomicBoolean filterInvoked = new AtomicBoolean();
WebFilter webFilter = (exchange, chain) -> {

View File

@@ -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,19 +45,19 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
*/
public class DefaultEntityResponseBuilderTests {
class DefaultEntityResponseBuilderTests {
static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList();
@Test
public void fromObject() {
void fromObject() {
String body = "foo";
EntityResponse<String> response = EntityResponse.fromObject(body).build();
assertThat(response.entity()).isSameAs(body);
}
@Test
public void fromObjectTypeReference() {
void fromObjectTypeReference() {
String body = "foo";
EntityResponse<String> response = EntityResponse.fromObject(body,
new ParameterizedTypeReference<String>() {})
@@ -67,7 +67,8 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void status() {
@SuppressWarnings("deprecation")
void status() {
String body = "foo";
EntityResponse<String> result =
EntityResponse.fromObject(body).status(HttpStatus.CREATED).build();
@@ -77,7 +78,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void allow() {
void allow() {
String body = "foo";
EntityResponse<String> result =
EntityResponse.fromObject(body).allow(HttpMethod.GET).build();
@@ -86,14 +87,14 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void contentLength() {
void contentLength() {
String body = "foo";
EntityResponse<String> result = EntityResponse.fromObject(body).contentLength(42).build();
assertThat(result.headers().getContentLength()).isEqualTo(42);
}
@Test
public void contentType() {
void contentType() {
String body = "foo";
EntityResponse<String>
result =
@@ -103,7 +104,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void etag() {
void etag() {
String body = "foo";
EntityResponse<String> result = EntityResponse.fromObject(body).eTag("foo").build();
@@ -111,7 +112,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void lastModified() {
void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
String body = "foo";
EntityResponse<String> result = EntityResponse.fromObject(body).lastModified(now).build();
@@ -120,7 +121,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void cacheControlTag() {
void cacheControlTag() {
String body = "foo";
EntityResponse<String> result =
EntityResponse.fromObject(body).cacheControl(CacheControl.noCache()).build();
@@ -128,7 +129,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void varyBy() {
void varyBy() {
String body = "foo";
EntityResponse<String> result = EntityResponse.fromObject(body).varyBy("foo").build();
List<String> expected = Collections.singletonList("foo");
@@ -136,14 +137,14 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void header() {
void header() {
String body = "foo";
EntityResponse<String> result = EntityResponse.fromObject(body).header("foo", "bar").build();
assertThat(result.headers().getFirst("foo")).isEqualTo("bar");
}
@Test
public void headers() {
void headers() {
String body = "foo";
HttpHeaders headers = new HttpHeaders();
headers.set("foo", "bar");
@@ -154,7 +155,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void cookie() {
void cookie() {
Cookie cookie = new Cookie("name", "value");
EntityResponse<String> result =
EntityResponse.fromObject("foo").cookie(cookie)
@@ -163,7 +164,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void cookies() {
void cookies() {
MultiValueMap<String, Cookie> newCookies = new LinkedMultiValueMap<>();
newCookies.add("name", new Cookie("name", "value"));
EntityResponse<String> result =
@@ -173,7 +174,7 @@ public class DefaultEntityResponseBuilderTests {
}
@Test
public void notModifiedEtag() throws Exception {
void notModifiedEtag() throws Exception {
String etag = "\"foo\"";
EntityResponse<String> entityResponse = EntityResponse.fromObject("bar")
.eTag(etag)
@@ -192,7 +193,7 @@ public class DefaultEntityResponseBuilderTests {
@Test
public void notModifiedLastModified() throws ServletException, IOException {
void notModifiedLastModified() throws ServletException, IOException {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);

View File

@@ -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.
@@ -51,19 +51,20 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
*/
public class DefaultServerResponseBuilderTests {
class DefaultServerResponseBuilderTests {
static final ServerResponse.Context EMPTY_CONTEXT = () -> Collections.emptyList();
@Test
public void status() {
@SuppressWarnings("deprecation")
void status() {
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.rawStatusCode()).isEqualTo(201);
}
@Test
public void from() {
void from() {
Cookie cookie = new Cookie("foo", "bar");
ServerResponse other = ServerResponse.ok()
.header("foo", "bar")
@@ -77,14 +78,14 @@ public class DefaultServerResponseBuilderTests {
@Test
public void ok() {
void ok() {
ServerResponse response = ServerResponse.ok().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK);
}
@Test
public void created() {
void created() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.created(location).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED);
@@ -92,19 +93,19 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void accepted() {
void accepted() {
ServerResponse response = ServerResponse.accepted().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.ACCEPTED);
}
@Test
public void noContent() {
void noContent() {
ServerResponse response = ServerResponse.noContent().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.NO_CONTENT);
}
@Test
public void seeOther() {
void seeOther() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.seeOther(location).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.SEE_OTHER);
@@ -112,7 +113,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void temporaryRedirect() {
void temporaryRedirect() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.temporaryRedirect(location).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.TEMPORARY_REDIRECT);
@@ -120,7 +121,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void permanentRedirect() {
void permanentRedirect() {
URI location = URI.create("https://example.com");
ServerResponse response = ServerResponse.permanentRedirect(location).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.PERMANENT_REDIRECT);
@@ -128,49 +129,49 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void badRequest() {
void badRequest() {
ServerResponse response = ServerResponse.badRequest().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
}
@Test
public void notFound() {
void notFound() {
ServerResponse response = ServerResponse.notFound().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
@Test
public void unprocessableEntity() {
void unprocessableEntity() {
ServerResponse response = ServerResponse.unprocessableEntity().build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
}
@Test
public void allow() {
void allow() {
ServerResponse response = ServerResponse.ok().allow(HttpMethod.GET).build();
assertThat(response.headers().getAllow()).isEqualTo(Set.of(HttpMethod.GET));
}
@Test
public void contentLength() {
void contentLength() {
ServerResponse response = ServerResponse.ok().contentLength(42).build();
assertThat(response.headers().getContentLength()).isEqualTo(42L);
}
@Test
public void contentType() {
void contentType() {
ServerResponse response = ServerResponse.ok().contentType(MediaType.APPLICATION_JSON).build();
assertThat(response.headers().getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
}
@Test
public void eTag() {
void eTag() {
ServerResponse response = ServerResponse.ok().eTag("foo").build();
assertThat(response.headers().getETag()).isEqualTo("\"foo\"");
}
@Test
public void lastModified() {
void lastModified() {
ZonedDateTime now = ZonedDateTime.now();
ServerResponse response = ServerResponse.ok().lastModified(now).build();
long expected = now.toInstant().toEpochMilli() / 1000;
@@ -178,28 +179,27 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void cacheControlTag() {
void cacheControlTag() {
ServerResponse response = ServerResponse.ok().cacheControl(CacheControl.noCache()).build();
assertThat(response.headers().getCacheControl()).isEqualTo("no-cache");
}
@Test
public void varyBy() {
void varyBy() {
ServerResponse response = ServerResponse.ok().varyBy("foo").build();
List<String> expected = Collections.singletonList("foo");
assertThat(response.headers().getVary()).isEqualTo(expected);
}
@Test
public void statusCode() {
void statusCode() {
HttpStatus statusCode = HttpStatus.ACCEPTED;
ServerResponse response = ServerResponse.status(statusCode).build();
assertThat(response.statusCode()).isEqualTo(statusCode);
}
@Test
public void headers() {
void headers() {
HttpHeaders newHeaders = new HttpHeaders();
newHeaders.set("foo", "bar");
ServerResponse response = ServerResponse.ok()
@@ -209,7 +209,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void cookies() {
void cookies() {
MultiValueMap<String, Cookie> newCookies = new LinkedMultiValueMap<>();
newCookies.add("name", new Cookie("name", "value"));
ServerResponse response = ServerResponse.ok()
@@ -219,7 +219,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void build() throws Exception {
void build() throws Exception {
Cookie cookie = new Cookie("name", "value");
ServerResponse response = ServerResponse.status(HttpStatus.CREATED)
.header("MyKey", "MyValue")
@@ -238,7 +238,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void notModifiedEtag() throws Exception {
void notModifiedEtag() throws Exception {
String etag = "\"foo\"";
ServerResponse response = ServerResponse.ok()
.eTag(etag)
@@ -255,7 +255,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void notModifiedLastModified() throws Exception {
void notModifiedLastModified() throws Exception {
ZonedDateTime now = ZonedDateTime.now();
ZonedDateTime oneMinuteBeforeNow = now.minus(1, ChronoUnit.MINUTES);
@@ -274,7 +274,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void body() throws Exception {
void body() throws Exception {
String body = "foo";
ServerResponse response = ServerResponse.ok().body(body);
@@ -289,7 +289,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void bodyWithParameterizedTypeReference() throws Exception {
void bodyWithParameterizedTypeReference() throws Exception {
List<String> body = new ArrayList<>();
body.add("foo");
body.add("bar");
@@ -306,7 +306,7 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void bodyCompletionStage() throws Exception {
void bodyCompletionStage() throws Exception {
String body = "foo";
CompletionStage<String> completionStage = CompletableFuture.completedFuture(body);
ServerResponse response = ServerResponse.ok().body(completionStage);
@@ -320,12 +320,11 @@ public class DefaultServerResponseBuilderTests {
ModelAndView mav = response.writeTo(mockRequest, mockResponse, context);
assertThat(mav).isNull();
assertThat(mockResponse.getContentAsString()).isEqualTo(body);
}
@Test
public void bodyPublisher() throws Exception {
void bodyPublisher() throws Exception {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
ServerResponse response = ServerResponse.ok().body(publisher);