Merge branch '6.2.x'

Closes gh-34286
This commit is contained in:
Sam Brannen
2025-01-20 17:10:14 +01:00
2 changed files with 42 additions and 39 deletions

View File

@@ -86,7 +86,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
*/
public HttpHeadersAssert containsOnlyHeaders(String... names) {
this.namesAssert
.as("check headers contains only HTTP headers '%s'", Arrays.toString(names))
.as("check headers contain only HTTP headers '%s'", Arrays.toString(names))
.containsOnly(names);
return this.myself;
}
@@ -98,7 +98,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
*/
public HttpHeadersAssert doesNotContainHeader(String name) {
this.namesAssert
.as("check headers does not contain HTTP header '%s'", name)
.as("check headers do not contain HTTP header '%s'", name)
.doesNotContain(name);
return this.myself;
}
@@ -111,7 +111,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
*/
public HttpHeadersAssert doesNotContainHeaders(String... names) {
this.namesAssert
.as("check headers does not contain HTTP headers '%s'", Arrays.toString(names))
.as("check headers do not contain HTTP headers '%s'", Arrays.toString(names))
.doesNotContain(names);
return this.myself;
}
@@ -119,15 +119,16 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
/**
* Verify that the actual HTTP headers contain a header with the given
* {@code name} that satisfies the given {@code valueRequirements}.
* @param name the name of an HTTP header that should not be present
* @param name the name of the header
* @param valueRequirements the group of assertions to run against the
* values of the header with the given name
* @since 7.0
*/
@SuppressWarnings("unchecked")
public HttpHeadersAssert hasHeaderSatisfying(String name, Consumer<List<String>> valueRequirements) {
containsHeader(name);
Assertions.assertThat(this.actual.get(name))
.as("check primary value for HTTP header '%s'", name)
.as("check all values for HTTP header '%s'", name)
.satisfies(values -> valueRequirements.accept((List<String>) values));
return this.myself;
}
@@ -135,7 +136,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
/**
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link String} primary {@code value}.
* @param name the name of the cookie
* @param name the name of the header
* @param value the expected value of the header
*/
public HttpHeadersAssert hasValue(String name, String value) {
@@ -148,8 +149,8 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
/**
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link Long} primary {@code value}.
* @param name the name of the cookie
* {@code name} and {@code long} primary {@code value}.
* @param name the name of the header
* @param value the expected value of the header
*/
public HttpHeadersAssert hasValue(String name, long value) {
@@ -163,7 +164,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
/**
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link Instant} primary {@code value}.
* @param name the name of the cookie
* @param name the name of the header
* @param value the expected value of the header
*/
public HttpHeadersAssert hasValue(String name, Instant value) {
@@ -178,7 +179,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link String} primary {@code value}.
* <p>This assertion fails if the header has secondary values.
* @param name the name of the cookie
* @param name the name of the header
* @param value the expected only value of the header
* @since 7.0
*/
@@ -189,9 +190,9 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
/**
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link Long} primary {@code value}.
* {@code name} and {@code long} primary {@code value}.
* <p>This assertion fails if the header has secondary values.
* @param name the name of the cookie
* @param name the name of the header
* @param value the expected value of the header
* @since 7.0
*/
@@ -204,7 +205,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
* Verify that the actual HTTP headers contain a header with the given
* {@code name} and {@link Instant} primary {@code value}.
* <p>This assertion fails if the header has secondary values.
* @param name the name of the cookie
* @param name the name of the header
* @param value the expected value of the header
* @since 7.0
*/
@@ -265,7 +266,7 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
}
/**
* Verify that there is exactly {@code expected} headers present, when
* Verify that there are exactly {@code expected} headers present, when
* considering header names in a case-insensitive manner.
* @param expected the expected number of headers
*/
@@ -293,11 +294,13 @@ public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, H
private HttpHeadersAssert doesNotHaveSecondaryValues(String name) {
containsHeader(name);
List<String> values = this.actual.get(name);
int size = (values != null) ? values.size() : 0;
Assertions.assertThat(size)
.withFailMessage("Expected HTTP header '%s' to be present " +
"without secondary values, but found <%s> secondary values", name, size - 1)
.isOne();
if (values != null && !values.isEmpty()) {
int size = values.size();
Assertions.assertThat(size)
.withFailMessage("Expected HTTP header '%s' to be present " +
"without secondary values, but found <%s> secondary value(s)", name, size - 1)
.isOne();
}
return this.myself;
}