Merge branch '5.3.x'
# Conflicts: # spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java
This commit is contained in:
commit
afd0443204
|
@ -50,6 +50,7 @@ import org.springframework.util.MultiValueMap;
|
||||||
* respectively.
|
* respectively.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
* @author Sam Brannen
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
* @see EntityExchangeResult
|
* @see EntityExchangeResult
|
||||||
* @see FluxExchangeResult
|
* @see FluxExchangeResult
|
||||||
|
@ -168,7 +169,6 @@ public class ExchangeResult {
|
||||||
return this.requestBody.block(this.timeout);
|
return this.requestBody.block(this.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the HTTP status code as an {@link HttpStatusCode} value.
|
* Return the HTTP status code as an {@link HttpStatusCode} value.
|
||||||
*/
|
*/
|
||||||
|
@ -249,20 +249,19 @@ public class ExchangeResult {
|
||||||
"\n" +
|
"\n" +
|
||||||
formatBody(getRequestHeaders().getContentType(), this.requestBody) + "\n" +
|
formatBody(getRequestHeaders().getContentType(), this.requestBody) + "\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"< " + getStatus() + " " + getReasonPhrase(getStatus()) + "\n" +
|
"< " + formatStatus(getStatus()) + "\n" +
|
||||||
"< " + formatHeaders(getResponseHeaders(), "\n< ") + "\n" +
|
"< " + formatHeaders(getResponseHeaders(), "\n< ") + "\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
formatBody(getResponseHeaders().getContentType(), this.responseBody) +"\n" +
|
formatBody(getResponseHeaders().getContentType(), this.responseBody) +"\n" +
|
||||||
formatMockServerResult();
|
formatMockServerResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getReasonPhrase(HttpStatusCode statusCode) {
|
private String formatStatus(HttpStatusCode statusCode) {
|
||||||
|
String result = statusCode.toString();
|
||||||
if (statusCode instanceof HttpStatus status) {
|
if (statusCode instanceof HttpStatus status) {
|
||||||
return status.getReasonPhrase();
|
result += " " + status.getReasonPhrase();
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatHeaders(HttpHeaders headers, String delimiter) {
|
private String formatHeaders(HttpHeaders headers, String delimiter) {
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock;
|
||||||
* Unit tests for {@link StatusAssertions}.
|
* Unit tests for {@link StatusAssertions}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
class StatusAssertionTests {
|
class StatusAssertionTests {
|
||||||
|
|
||||||
|
@ -56,9 +57,20 @@ class StatusAssertionTests {
|
||||||
assertions.isEqualTo(408));
|
assertions.isEqualTo(408));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // gh-23630
|
@Test // gh-23630, gh-29283
|
||||||
void isEqualToWithCustomStatus() {
|
void isEqualToWithCustomStatus() {
|
||||||
statusAssertions(600).isEqualTo(600);
|
StatusAssertions assertions = statusAssertions(600);
|
||||||
|
|
||||||
|
// Success
|
||||||
|
// assertions.isEqualTo(600);
|
||||||
|
|
||||||
|
// Wrong status
|
||||||
|
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
|
||||||
|
assertions.isEqualTo(HttpStatus.REQUEST_TIMEOUT));
|
||||||
|
|
||||||
|
// Wrong status value
|
||||||
|
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
|
||||||
|
assertions.isEqualTo(408));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue