Add headerDoesNotExist() to MockRestRequestMatchers

Prior to this commit, one could not test for the absence of a specific
HTTP header in a request.

This commit adds a headerDoesNotExist() method in MockRestRequestMatchers.

Closes gh-23721
This commit is contained in:
Sam Brannen
2019-09-27 17:38:11 +02:00
parent 4dc966b04b
commit 06563d8b4b
2 changed files with 28 additions and 0 deletions

View File

@@ -185,6 +185,20 @@ public abstract class MockRestRequestMatchers {
};
}
/**
* Assert that the given request header does not exist.
* @since 5.2
*/
public static RequestMatcher headerDoesNotExist(String name) {
return request -> {
List<String> headerValues = request.getHeaders().get(name);
if (headerValues != null) {
fail("Expected header <" + name + "> not to exist, but it exists with values: " +
headerValues);
}
};
}
/**
* Access to request body matchers.
*/