Add doesExist() to HeaderAssertions for WebTestClient
This commit is contained in:
@@ -32,6 +32,7 @@ import static org.springframework.test.util.AssertionErrors.*;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
* @author Sam Brannen
|
||||
* @since 5.0
|
||||
* @see WebTestClient.ResponseSpec#expectHeader()
|
||||
*/
|
||||
@@ -72,6 +73,18 @@ public class HeaderAssertions {
|
||||
return this.responseSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect that the header with the given name is present.
|
||||
* @since 5.0.3
|
||||
*/
|
||||
public WebTestClient.ResponseSpec doesExist(String name) {
|
||||
if (!getHeaders().containsKey(name)) {
|
||||
String message = getMessage(name) + " does not exist";
|
||||
this.exchangeResult.assertWithDiagnostics(() -> fail(message));
|
||||
}
|
||||
return this.responseSpec;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect that the header with the given name is not present.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user