Add doesNotExist match to HeaderResultMatchers
Prior to this commit, one could not test for the absence of
a specific HTTP header in a response.
Using header("X-Custom-Header", Matchers.nullValue()) would not
work because it tests for an empty value of an existing header.
This commit adds a doesNotExist method on the
HeaderResultMatcher.
Issue: SPR-10771
This commit is contained in:
committed by
Rossen Stoyanchev
parent
e4479c8669
commit
4bf5a0234c
@@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
|
||||
|
||||
/**
|
||||
* Examples of expectations on response header values.
|
||||
*
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
@@ -110,6 +110,22 @@ public class HeaderAssertionTests {
|
||||
}
|
||||
}
|
||||
|
||||
// SPR-10771
|
||||
|
||||
@Test
|
||||
public void doesNotExist() throws Exception {
|
||||
this.mockMvc.perform(get("/persons/1"))
|
||||
.andExpect(header().doesNotExist("X-Custom-Header"));
|
||||
}
|
||||
|
||||
// SPR-10771
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void doesNotExistFail() throws Exception {
|
||||
this.mockMvc.perform(get("/persons/1"))
|
||||
.andExpect(header().doesNotExist(LAST_MODIFIED));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringWithIncorrectResponseHeaderValue() throws Exception {
|
||||
long unexpected = currentTime + 1;
|
||||
|
||||
Reference in New Issue
Block a user