Skip to content

Commit 8270d82

Browse files
committed
Fix failing test
Issue: SPR-7905
1 parent c7e7e80 commit 8270d82

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

spring-test-mvc/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ protected ContentRequestMatchers() {
5656
/**
5757
* Assert the request content type as a String.
5858
*/
59-
public RequestMatcher mimeType(String expectedContentType) {
60-
return mimeType(MediaType.parseMediaType(expectedContentType));
59+
public RequestMatcher contentType(String expectedContentType) {
60+
return contentType(MediaType.parseMediaType(expectedContentType));
6161
}
6262

6363
/**
6464
* Assert the request content type as a {@link MediaType}.
6565
*/
66-
public RequestMatcher mimeType(final MediaType expectedContentType) {
66+
public RequestMatcher contentType(final MediaType expectedContentType) {
6767
return new RequestMatcher() {
6868
public void match(ClientHttpRequest request) throws IOException, AssertionError {
6969
MediaType actualContentType = request.getHeaders().getContentType();

spring-test-mvc/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ public void setUp() {
4242
public void testContentType() throws Exception {
4343
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
4444

45-
MockRestRequestMatchers.content().mimeType("application/json").match(this.request);
46-
MockRestRequestMatchers.content().mimeType(MediaType.APPLICATION_JSON).match(this.request);
45+
MockRestRequestMatchers.content().contentType("application/json").match(this.request);
46+
MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_JSON).match(this.request);
4747
}
4848

4949
@Test(expected=AssertionError.class)
5050
public void testContentTypeNoMatch1() throws Exception {
5151
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
5252

53-
MockRestRequestMatchers.content().mimeType("application/xml").match(this.request);
53+
MockRestRequestMatchers.content().contentType("application/xml").match(this.request);
5454
}
5555

5656
@Test(expected=AssertionError.class)
5757
public void testContentTypeNoMatch2() throws Exception {
5858
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
5959

60-
MockRestRequestMatchers.content().mimeType(MediaType.APPLICATION_ATOM_XML).match(this.request);
60+
MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_ATOM_XML).match(this.request);
6161
}
6262

6363
@Test

spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ public void setup() {
6262

6363
@Test
6464
public void contentType() throws Exception {
65-
this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess());
65+
this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess());
6666
this.restTemplate.put(new URI("/foo"), new Person());
6767
this.mockServer.verify();
6868
}
6969

7070
@Test
7171
public void contentTypeNoMatch() throws Exception {
72-
this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess());
72+
this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess());
7373
try {
7474
this.restTemplate.put(new URI("/foo"), "foo");
7575
}

spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/HeaderRequestMatcherTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void setup() {
6363
public void testString() throws Exception {
6464

6565
this.mockServer.expect(requestTo("/person/1"))
66-
.andExpect(header("Accept", "application/json"))
66+
.andExpect(header("Accept", "application/json, application/*+json"))
6767
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
6868

6969
this.restTemplate.getForObject(new URI("/person/1"), Person.class);

spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void setup() {
7777
@Test
7878
public void testExists() throws Exception {
7979
this.mockServer.expect(requestTo("/composers"))
80-
.andExpect(content().mimeType("application/json;charset=UTF-8"))
80+
.andExpect(content().contentType("application/json;charset=UTF-8"))
8181
.andExpect(jsonPath("$.composers[0]").exists())
8282
.andExpect(jsonPath("$.composers[1]").exists())
8383
.andExpect(jsonPath("$.composers[2]").exists())
@@ -91,7 +91,7 @@ public void testExists() throws Exception {
9191
@Test
9292
public void testDoesNotExist() throws Exception {
9393
this.mockServer.expect(requestTo("/composers"))
94-
.andExpect(content().mimeType("application/json;charset=UTF-8"))
94+
.andExpect(content().contentType("application/json;charset=UTF-8"))
9595
.andExpect(jsonPath("$.composers[?(@.name = 'Edvard Grieeeeeeg')]").doesNotExist())
9696
.andExpect(jsonPath("$.composers[?(@.name = 'Robert Schuuuuuuman')]").doesNotExist())
9797
.andExpect(jsonPath("$.composers[-1]").doesNotExist())
@@ -105,7 +105,7 @@ public void testDoesNotExist() throws Exception {
105105
@Test
106106
public void testEqualTo() throws Exception {
107107
this.mockServer.expect(requestTo("/composers"))
108-
.andExpect(content().mimeType("application/json;charset=UTF-8"))
108+
.andExpect(content().contentType("application/json;charset=UTF-8"))
109109
.andExpect(jsonPath("$.composers[0].name").value("Johann Sebastian Bach"))
110110
.andExpect(jsonPath("$.performers[1].name").value("Yehudi Menuhin"))
111111
.andExpect(jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach"))) // Hamcrest
@@ -119,7 +119,7 @@ public void testEqualTo() throws Exception {
119119
@Test
120120
public void testHamcrestMatcher() throws Exception {
121121
this.mockServer.expect(requestTo("/composers"))
122-
.andExpect(content().mimeType("application/json;charset=UTF-8"))
122+
.andExpect(content().contentType("application/json;charset=UTF-8"))
123123
.andExpect(jsonPath("$.composers[0].name", startsWith("Johann")))
124124
.andExpect(jsonPath("$.performers[0].name", endsWith("Ashkenazy")))
125125
.andExpect(jsonPath("$.performers[1].name", containsString("di Me")))
@@ -136,7 +136,7 @@ public void testHamcrestMatcherWithParameterizedJsonPath() throws Exception {
136136
String performerName = "$.performers[%s].name";
137137

138138
this.mockServer.expect(requestTo("/composers"))
139-
.andExpect(content().mimeType("application/json;charset=UTF-8"))
139+
.andExpect(content().contentType("application/json;charset=UTF-8"))
140140
.andExpect(jsonPath(composerName, 0).value(startsWith("Johann")))
141141
.andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy")))
142142
.andExpect(jsonPath(performerName, 1).value(containsString("di Me")))

spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void setup() {
8989
@Test
9090
public void testXmlEqualTo() throws Exception {
9191
this.mockServer.expect(requestTo("/composers"))
92-
.andExpect(content().mimeType("application/xml"))
92+
.andExpect(content().contentType("application/xml"))
9393
.andExpect(content().xml(PEOPLE_XML))
9494
.andRespond(withSuccess());
9595

@@ -101,7 +101,7 @@ public void testXmlEqualTo() throws Exception {
101101
public void testHamcrestNodeMatcher() throws Exception {
102102

103103
this.mockServer.expect(requestTo("/composers"))
104-
.andExpect(content().mimeType("application/xml"))
104+
.andExpect(content().contentType("application/xml"))
105105
.andExpect(content().node(hasXPath("/people/composers/composer[1]")))
106106
.andRespond(withSuccess());
107107

spring-test-mvc/src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void testExists() throws Exception {
9797
String performer = "/ns:people/performers/performer[%s]";
9898

9999
this.mockServer.expect(requestTo("/composers"))
100-
.andExpect(content().mimeType("application/xml"))
100+
.andExpect(content().contentType("application/xml"))
101101
.andExpect(xpath(composer, NS, 1).exists())
102102
.andExpect(xpath(composer, NS, 2).exists())
103103
.andExpect(xpath(composer, NS, 3).exists())
@@ -117,7 +117,7 @@ public void testDoesNotExist() throws Exception {
117117
String performer = "/ns:people/performers/performer[%s]";
118118

119119
this.mockServer.expect(requestTo("/composers"))
120-
.andExpect(content().mimeType("application/xml"))
120+
.andExpect(content().contentType("application/xml"))
121121
.andExpect(xpath(composer, NS, 0).doesNotExist())
122122
.andExpect(xpath(composer, NS, 5).doesNotExist())
123123
.andExpect(xpath(performer, NS, 0).doesNotExist())
@@ -135,7 +135,7 @@ public void testString() throws Exception {
135135
String performerName = "/ns:people/performers/performer[%s]/name";
136136

137137
this.mockServer.expect(requestTo("/composers"))
138-
.andExpect(content().mimeType("application/xml"))
138+
.andExpect(content().contentType("application/xml"))
139139
.andExpect(xpath(composerName, NS, 1).string("Johann Sebastian Bach"))
140140
.andExpect(xpath(composerName, NS, 2).string("Johannes Brahms"))
141141
.andExpect(xpath(composerName, NS, 3).string("Edvard Grieg"))
@@ -157,7 +157,7 @@ public void testNumber() throws Exception {
157157
String composerDouble = "/ns:people/composers/composer[%s]/someDouble";
158158

159159
this.mockServer.expect(requestTo("/composers"))
160-
.andExpect(content().mimeType("application/xml"))
160+
.andExpect(content().contentType("application/xml"))
161161
.andExpect(xpath(composerDouble, NS, 1).number(21d))
162162
.andExpect(xpath(composerDouble, NS, 2).number(.0025))
163163
.andExpect(xpath(composerDouble, NS, 3).number(1.6035))
@@ -176,7 +176,7 @@ public void testBoolean() throws Exception {
176176
String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean";
177177

178178
this.mockServer.expect(requestTo("/composers"))
179-
.andExpect(content().mimeType("application/xml"))
179+
.andExpect(content().contentType("application/xml"))
180180
.andExpect(xpath(performerBooleanValue, NS, 1).booleanValue(false))
181181
.andExpect(xpath(performerBooleanValue, NS, 2).booleanValue(true))
182182
.andRespond(withSuccess());
@@ -189,7 +189,7 @@ public void testBoolean() throws Exception {
189189
public void testNodeCount() throws Exception {
190190

191191
this.mockServer.expect(requestTo("/composers"))
192-
.andExpect(content().mimeType("application/xml"))
192+
.andExpect(content().contentType("application/xml"))
193193
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4))
194194
.andExpect(xpath("/ns:people/performers/performer", NS).nodeCount(2))
195195
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(lessThan(5))) // Hamcrest..

0 commit comments

Comments
 (0)