Add doesExist() to HeaderAssertions for WebTestClient

This commit is contained in:
Sam Brannen
2018-01-25 15:50:19 +01:00
parent 431494096a
commit 165ca12e6d
2 changed files with 35 additions and 1 deletions

View File

@@ -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.
*/