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:
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user