Skip to content

Commit b612f53

Browse files
committed
Rename doesExist() to exists() for header assertions
1 parent 0e734d8 commit b612f53

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public WebTestClient.ResponseSpec valueMatches(String name, String pattern) {
7777
* Expect that the header with the given name is present.
7878
* @since 5.0.3
7979
*/
80-
public WebTestClient.ResponseSpec doesExist(String name) {
80+
public WebTestClient.ResponseSpec exists(String name) {
8181
if (!getHeaders().containsKey(name)) {
8282
String message = getMessage(name) + " does not exist";
8383
this.exchangeResult.assertWithDiagnostics(() -> fail(message));

spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ public ResultMatcher stringValues(final String name, final String... values) {
9191
}
9292

9393
/**
94-
* Assert that the named response header does exist.
94+
* Assert that the named response header exists.
9595
* @since 5.0.3
9696
*/
97-
public ResultMatcher doesExist(final String name) {
97+
public ResultMatcher exists(final String name) {
9898
return result -> assertTrue("Response should contain header '" + name + "'",
9999
result.getResponse().containsHeader(name));
100100
}

spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,16 @@ public void valueMatches() {
126126
}
127127

128128
@Test
129-
public void doesExist() {
129+
public void exists() {
130130
HttpHeaders headers = new HttpHeaders();
131131
headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
132132
HeaderAssertions assertions = headerAssertions(headers);
133133

134134
// Success
135-
assertions.doesExist("Content-Type");
135+
assertions.exists("Content-Type");
136136

137137
try {
138-
assertions.doesExist("Framework");
138+
assertions.exists("Framework");
139139
fail("Header should not exist");
140140
}
141141
catch (AssertionError error) {

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/HeaderAssertionTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ public void longValueWithMissingResponseHeader() throws Exception {
144144
}
145145
}
146146

147+
@Test
148+
public void exists() throws Exception {
149+
this.mockMvc.perform(get("/persons/1")).andExpect(header().exists(LAST_MODIFIED));
150+
}
151+
152+
@Test(expected = AssertionError.class)
153+
public void existsFail() throws Exception {
154+
this.mockMvc.perform(get("/persons/1")).andExpect(header().exists("X-Custom-Header"));
155+
}
156+
147157
@Test // SPR-10771
148158
public void doesNotExist() throws Exception {
149159
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist("X-Custom-Header"));
@@ -154,16 +164,6 @@ public void doesNotExistFail() throws Exception {
154164
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesNotExist(LAST_MODIFIED));
155165
}
156166

157-
@Test
158-
public void doesExist() throws Exception {
159-
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesExist(LAST_MODIFIED));
160-
}
161-
162-
@Test(expected = AssertionError.class)
163-
public void doesExistFail() throws Exception {
164-
this.mockMvc.perform(get("/persons/1")).andExpect(header().doesExist("X-Custom-Header"));
165-
}
166-
167167
@Test
168168
public void stringWithIncorrectResponseHeaderValue() throws Exception {
169169
assertIncorrectResponseHeader(header().string(LAST_MODIFIED, secondLater), secondLater);

0 commit comments

Comments
 (0)