Merge pull request #1649 from neonailol/header-does-exist-matcher

This commit is contained in:
Rossen Stoyanchev 2018-01-24 17:39:15 -05:00
commit 5d25ca29a6
2 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -90,6 +90,15 @@ public class HeaderResultMatchers {
};
}
/**
* Assert that the named response header does exist.
* @since 5.0.3
*/
public ResultMatcher doesExist(final String name) {
return result -> assertTrue("Response should contain header '" + name + "'",
result.getResponse().containsHeader(name));
}
/**
* Assert that the named response header does not exist.
* @since 4.0

View File

@ -154,6 +154,16 @@ public class HeaderAssertionTests {
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist(LAST_MODIFIED));
}
@Test
public void doesExist() throws Exception {
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesExist(LAST_MODIFIED));
}
@Test(expected = AssertionError.class)
public void doesExistFail() throws Exception {
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesExist("X-Custom-Header"));
}
@Test
public void stringWithIncorrectResponseHeaderValue() throws Exception {
assertIncorrectResponseHeader(header().string(LAST_MODIFIED, secondLater), secondLater);