Rename doesExist() to exists() for header assertions
This commit is contained in:
parent
0e734d83d5
commit
b612f53e27
|
|
@ -77,7 +77,7 @@ public class HeaderAssertions {
|
||||||
* Expect that the header with the given name is present.
|
* Expect that the header with the given name is present.
|
||||||
* @since 5.0.3
|
* @since 5.0.3
|
||||||
*/
|
*/
|
||||||
public WebTestClient.ResponseSpec doesExist(String name) {
|
public WebTestClient.ResponseSpec exists(String name) {
|
||||||
if (!getHeaders().containsKey(name)) {
|
if (!getHeaders().containsKey(name)) {
|
||||||
String message = getMessage(name) + " does not exist";
|
String message = getMessage(name) + " does not exist";
|
||||||
this.exchangeResult.assertWithDiagnostics(() -> fail(message));
|
this.exchangeResult.assertWithDiagnostics(() -> fail(message));
|
||||||
|
|
|
||||||
|
|
@ -91,10 +91,10 @@ public class HeaderResultMatchers {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assert that the named response header does exist.
|
* Assert that the named response header exists.
|
||||||
* @since 5.0.3
|
* @since 5.0.3
|
||||||
*/
|
*/
|
||||||
public ResultMatcher doesExist(final String name) {
|
public ResultMatcher exists(final String name) {
|
||||||
return result -> assertTrue("Response should contain header '" + name + "'",
|
return result -> assertTrue("Response should contain header '" + name + "'",
|
||||||
result.getResponse().containsHeader(name));
|
result.getResponse().containsHeader(name));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,16 +126,16 @@ public class HeaderAssertionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void doesExist() {
|
public void exists() {
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
||||||
HeaderAssertions assertions = headerAssertions(headers);
|
HeaderAssertions assertions = headerAssertions(headers);
|
||||||
|
|
||||||
// Success
|
// Success
|
||||||
assertions.doesExist("Content-Type");
|
assertions.exists("Content-Type");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
assertions.doesExist("Framework");
|
assertions.exists("Framework");
|
||||||
fail("Header should not exist");
|
fail("Header should not exist");
|
||||||
}
|
}
|
||||||
catch (AssertionError error) {
|
catch (AssertionError error) {
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,16 @@ public class HeaderAssertionTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void exists() throws Exception {
|
||||||
|
this.mockMvc.perform(get("/persons/1")).andExpect(header().exists(LAST_MODIFIED));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = AssertionError.class)
|
||||||
|
public void existsFail() throws Exception {
|
||||||
|
this.mockMvc.perform(get("/persons/1")).andExpect(header().exists("X-Custom-Header"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test // SPR-10771
|
@Test // SPR-10771
|
||||||
public void doesNotExist() throws Exception {
|
public void doesNotExist() throws Exception {
|
||||||
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist("X-Custom-Header"));
|
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist("X-Custom-Header"));
|
||||||
|
|
@ -154,16 +164,6 @@ public class HeaderAssertionTests {
|
||||||
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist(LAST_MODIFIED));
|
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
|
@Test
|
||||||
public void stringWithIncorrectResponseHeaderValue() throws Exception {
|
public void stringWithIncorrectResponseHeaderValue() throws Exception {
|
||||||
assertIncorrectResponseHeader(header().string(LAST_MODIFIED, secondLater), secondLater);
|
assertIncorrectResponseHeader(header().string(LAST_MODIFIED, secondLater), secondLater);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue