Merge branch '6.2.x'
Closes gh-34286
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ class HttpHeadersAssertTests {
|
||||
headers.add("name2", "value2");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).containsOnlyHeaders("name1", "name2", "name3"))
|
||||
.withMessageContainingAll("check headers contains only HTTP headers",
|
||||
.withMessageContainingAll("check headers contain only HTTP headers",
|
||||
"could not find the following element(s)", "[\"name3\"]");
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ class HttpHeadersAssertTests {
|
||||
headers.add("name3", "value3");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).containsOnlyHeaders("name1", "name2"))
|
||||
.withMessageContainingAll("check headers contains only HTTP headers",
|
||||
.withMessageContainingAll("check headers contain only HTTP headers",
|
||||
"the following element(s) were unexpected", "[\"name3\"]");
|
||||
}
|
||||
|
||||
@@ -185,10 +185,10 @@ class HttpHeadersAssertTests {
|
||||
|
||||
@Test
|
||||
void hasValueWithNonPresentHeader() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.add("test-header", "a");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("test-header", "a");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", "a"))
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("wrong-name", "a"))
|
||||
.withMessageContainingAll("HTTP header", "test-header", "wrong-name");
|
||||
}
|
||||
|
||||
@@ -201,19 +201,19 @@ class HttpHeadersAssertTests {
|
||||
|
||||
@Test
|
||||
void hasValueWithLongMatchOnSecondaryValue() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.addAll("header", List.of("123", "456", "789"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.addAll("header", List.of("123", "456", "789"));
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("header", 456))
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("header", 456))
|
||||
.withMessageContainingAll("check primary long value for HTTP header 'header'", "123", "456");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasValueWithNoLongMatch() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.addAll("header", List.of("123", "456", "789"));
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.addAll("header", List.of("123", "456", "789"));
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", 456))
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("wrong-name", 456))
|
||||
.withMessageContainingAll("HTTP header", "header", "wrong-name");
|
||||
}
|
||||
|
||||
@@ -228,20 +228,20 @@ class HttpHeadersAssertTests {
|
||||
@Test
|
||||
void hasValueWithNoInstantMatch() {
|
||||
Instant instant = Instant.now();
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.setInstant("header", instant);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setInstant("header", instant);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(30)))
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("wrong-name", instant.minusSeconds(30)))
|
||||
.withMessageContainingAll("HTTP header", "header", "wrong-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasValueWithNoInstantMatchOneSecOfDifference() {
|
||||
Instant instant = Instant.now();
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.setInstant("header", instant);
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setInstant("header", instant);
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(1)))
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("wrong-name", instant.minusSeconds(1)))
|
||||
.withMessageContainingAll("HTTP header", "header", "wrong-name");
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ class HttpHeadersAssertTests {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).hasSingleValue("header", "first"))
|
||||
.withMessage("Expected HTTP header 'header' to be present without secondary values, " +
|
||||
"but found <2> secondary values");
|
||||
"but found <2> secondary value(s)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -276,7 +276,7 @@ class HttpHeadersAssertTests {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).hasSingleValue("header", 123))
|
||||
.withMessage("Expected HTTP header 'header' to be present without secondary values, " +
|
||||
"but found <2> secondary values");
|
||||
"but found <2> secondary value(s)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,7 +296,7 @@ class HttpHeadersAssertTests {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).hasSingleValue("header", instant.minusSeconds(30)))
|
||||
.withMessage("Expected HTTP header 'header' to be present without secondary values, " +
|
||||
"but found <1> secondary values");
|
||||
"but found <1> secondary value(s)");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user