Browse files

Rename methods called type to mimeType

Method in result and request matchers named type() are now called
mimeType() to prevent a clash with the "type" keyword word in Scala.
  • Loading branch information...
1 parent 9eb3acb commit d2510b7b390a0703ec8853e93eeed1664c29d189 @rstoyanchev rstoyanchev committed Sep 13, 2012
Showing with 61 additions and 61 deletions.
  1. +2 −2 README.md
  2. +3 −3 src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java
  3. +1 −1 src/main/java/org/springframework/test/web/server/MockMvc.java
  4. +10 −10 src/main/java/org/springframework/test/web/server/ResultActions.java
  5. +8 −8 src/main/java/org/springframework/test/web/server/ResultMatcher.java
  6. +3 −3 src/main/java/org/springframework/test/web/server/result/ContentResultMatchers.java
  7. +1 −1 src/main/java/org/springframework/test/web/server/result/HandlerResultMatchers.java
  8. +4 −4 src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java
  9. +2 −2 src/test/java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java
  10. +5 −5 src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java
  11. +2 −2 ...test/java/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java
  12. +6 −6 src/test/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java
  13. +2 −2 src/test/java/org/springframework/test/web/server/result/ContentResultMatchersTests.java
  14. +2 −2 src/test/java/org/springframework/test/web/server/samples/context/WarRootDirectoryTests.java
  15. +1 −1 src/test/java/org/springframework/test/web/server/samples/standalone/ResponseBodyTests.java
  16. +4 −4 src/test/java/org/springframework/test/web/server/samples/standalone/ViewResolutionTests.java
  17. +4 −4 .../springframework/test/web/server/samples/standalone/resultmatchers/ContentResultMatcherTests.java
  18. +1 −1 .../springframework/test/web/server/samples/standalone/resultmatchers/HandlerResultMatcherTests.java
View
4 README.md
@@ -24,7 +24,7 @@ Test an `@ResponseBody` method in a controller:
MockMvcBuilders.standaloneSetup(new TestController()).build()
.perform(get("/form"))
.andExpect(status().isOk())
- .andExpect(content().type("text/plain"))
+ .andExpect(content().mimeType("text/plain"))
.andExpect(content().string("hello world"));
Test binding failure by pointing to Spring MVC XML-based context configuration:
@@ -46,7 +46,7 @@ Test serving a resource by pointing to Spring MVC Java-based application configu
MockMvcBuilders.annotationConfigSetup(TestConfiguration.class).build()
.perform(get("/resources/Spring.js"))
- .andExpect(content().type("application/octet-stream"))
+ .andExpect(content().mimeType("application/octet-stream"))
.andExpect(content().string(containsString("Spring={};")));
The last example uses a Hamcrest matcher to check if the content contains specific text.
View
6 src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java
@@ -55,14 +55,14 @@ protected ContentRequestMatchers() {
/**
* Assert the request content type as a String.
*/
- public RequestMatcher type(String expectedContentType) {
- return type(MediaType.parseMediaType(expectedContentType));
+ public RequestMatcher mimeType(String expectedContentType) {
+ return mimeType(MediaType.parseMediaType(expectedContentType));
}
/**
* Assert the request content type as a {@link MediaType}.
*/
- public RequestMatcher type(final MediaType expectedContentType) {
+ public RequestMatcher mimeType(final MediaType expectedContentType) {
return new RequestMatcher() {
public void match(ClientHttpRequest request) throws IOException, AssertionError {
MediaType actualContentType = request.getHeaders().getContentType();
View
2 src/main/java/org/springframework/test/web/server/MockMvc.java
@@ -39,7 +39,7 @@
*
* mockMvc.perform(get("/form"))
* .andExpect(status().isOk())
- * .andExpect(content().type("text/plain"))
+ * .andExpect(content().mimeType("text/plain"))
* .andExpect(forwardedUrl("/WEB-INF/layouts/main.jsp"));
* </pre>
*
View
20 src/main/java/org/springframework/test/web/server/ResultActions.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -19,11 +19,11 @@
/**
* A contract for defining actions on the results of an executed request.
- *
+ *
* <p>See static factory methods in
* {@code org.springframework.test.web.server.result.MockMvcResultMatchers} and
* {@code org.springframework.test.web.server.result.MockMvcResultHandlers}.
- *
+ *
* @author Rossen Stoyanchev
*/
public interface ResultActions {
@@ -32,40 +32,40 @@
* Provide an expectation. For example:
* <pre>
* // Assuming static import of MockMvcResultMatchers.*
- *
+ *
* mockMvc.perform(get("/person/1"))
* .andExpect(status.isOk())
- * .andExpect(content().type(MediaType.APPLICATION_JSON))
+ * .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
* .andExpect(jsonPath("$.person.name").equalTo("Jason"));
- *
+ *
* mockMvc.perform(post("/form"))
* .andExpect(status.isOk())
* .andExpect(redirectedUrl("/person/1"))
* .andExpect(model().size(1))
* .andExpect(model().attributeExists("person"))
* .andExpect(flash().attributeCount(1))
* .andExpect(flash().attribute("message", "success!"));
- * </pre>
+ * </pre>
*/
ResultActions andExpect(ResultMatcher matcher) throws Exception;
/**
* Provide a general action. For example:
* <pre>
* // Assuming static imports of MockMvcResultHandlers.* and MockMvcResultMatchers.*
- *
+ *
* mockMvc.perform(get("/form"))
* .andDo(print()) // Print the results
* .andExpect(status.isOk())
* .andExpect(contentType(MediaType.APPLICATION_JSON));
* </pre>
*/
ResultActions andDo(ResultHandler handler) throws Exception;
-
+
/**
* TODO
* @return TODO
*/
MvcResult andReturn();
-
+
}
View
16 src/main/java/org/springframework/test/web/server/ResultMatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -19,19 +19,19 @@
/**
* A contract to match the results of an executed request against some expectation.
- *
- * <p>See static factory methods in
+ *
+ * <p>See static factory methods in
* {@code org.springframework.test.web.server.result.MockMvcResultActions}.
- *
+ *
* <p>Example, assuming a static import of {@code MockMvcRequestBuilders.*} and
* {@code MockMvcResultActions.*}:
- *
+ *
* <pre>
* mockMvc.perform(get("/form"))
* .andExpect(status.isOk())
- * .andExpect(content().type(MediaType.APPLICATION_JSON));
- * </pre>
- *
+ * .andExpect(content().mimeType(MediaType.APPLICATION_JSON));
+ * </pre>
+ *
* @author Rossen Stoyanchev
*/
public interface ResultMatcher {
View
6 src/main/java/org/springframework/test/web/server/result/ContentResultMatchers.java
@@ -52,14 +52,14 @@ public ContentResultMatchers() {
/**
* Assert the ServletResponse content type.
*/
- public ResultMatcher type(String contentType) {
- return type(MediaType.parseMediaType(contentType));
+ public ResultMatcher mimeType(String contentType) {
+ return mimeType(MediaType.parseMediaType(contentType));
}
/**
* Assert the ServletResponse content type after parsing it as a MediaType.
*/
- public ResultMatcher type(final MediaType contentType) {
+ public ResultMatcher mimeType(final MediaType contentType) {
return new ResultMatcher() {
public void match(MvcResult result) throws Exception {
String actual = result.getResponse().getContentType();
View
2 src/main/java/org/springframework/test/web/server/result/HandlerResultMatchers.java
@@ -34,7 +34,7 @@
/**
* TODO
*/
- public ResultMatcher type(final Class<?> type) {
+ public ResultMatcher handlerType(final Class<?> type) {
return new ResultMatcher() {
public void match(MvcResult result) throws Exception {
Object handler = result.getHandler();
View
8 src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java
@@ -41,22 +41,22 @@ public void setUp() {
public void testContentType() throws Exception {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
- RequestMatchers.content().type("application/json").match(this.request);
- RequestMatchers.content().type(MediaType.APPLICATION_JSON).match(this.request);
+ RequestMatchers.content().mimeType("application/json").match(this.request);
+ RequestMatchers.content().mimeType(MediaType.APPLICATION_JSON).match(this.request);
}
@Test(expected=AssertionError.class)
public void testContentTypeNoMatch1() throws Exception {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
- RequestMatchers.content().type("application/xml").match(this.request);
+ RequestMatchers.content().mimeType("application/xml").match(this.request);
}
@Test(expected=AssertionError.class)
public void testContentTypeNoMatch2() throws Exception {
this.request.getHeaders().setContentType(MediaType.APPLICATION_JSON);
- RequestMatchers.content().type(MediaType.APPLICATION_ATOM_XML).match(this.request);
+ RequestMatchers.content().mimeType(MediaType.APPLICATION_ATOM_XML).match(this.request);
}
@Test
View
4 ...java/org/springframework/test/web/client/samples/matchers/ContentRequestMatcherTests.java
@@ -62,14 +62,14 @@ public void setup() {
@Test
public void contentType() throws Exception {
- this.mockServer.expect(content().type("application/json;charset=UTF-8")).andRespond(withSuccess());
+ this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess());
this.restTemplate.put(new URI("/foo"), new Person());
this.mockServer.verify();
}
@Test
public void contentTypeNoMatch() throws Exception {
- this.mockServer.expect(content().type("application/json;charset=UTF-8")).andRespond(withSuccess());
+ this.mockServer.expect(content().mimeType("application/json;charset=UTF-8")).andRespond(withSuccess());
try {
this.restTemplate.put(new URI("/foo"), "foo");
}
View
10 ...ava/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatcherTests.java
@@ -80,7 +80,7 @@ public void setup() {
@Test
public void testExists() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/json;charset=UTF-8"))
+ .andExpect(content().mimeType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.composers[0]").exists())
.andExpect(jsonPath("$.composers[1]").exists())
.andExpect(jsonPath("$.composers[2]").exists())
@@ -94,7 +94,7 @@ public void testExists() throws Exception {
@Test
public void testDoesNotExist() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/json;charset=UTF-8"))
+ .andExpect(content().mimeType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.composers[?(@.name = 'Edvard Grieeeeeeg')]").doesNotExist())
.andExpect(jsonPath("$.composers[?(@.name = 'Robert Schuuuuuuman')]").doesNotExist())
.andExpect(jsonPath("$.composers[-1]").doesNotExist())
@@ -108,7 +108,7 @@ public void testDoesNotExist() throws Exception {
@Test
public void testEqualTo() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/json;charset=UTF-8"))
+ .andExpect(content().mimeType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.composers[0].name").value("Johann Sebastian Bach"))
.andExpect(jsonPath("$.performers[1].name").value("Yehudi Menuhin"))
.andExpect(jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach"))) // Hamcrest
@@ -122,7 +122,7 @@ public void testEqualTo() throws Exception {
@Test
public void testHamcrestMatcher() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/json;charset=UTF-8"))
+ .andExpect(content().mimeType("application/json;charset=UTF-8"))
.andExpect(jsonPath("$.composers", hasSize(4)))
.andExpect(jsonPath("$.performers", hasSize(equalTo(2))))
.andExpect(jsonPath("$.composers[?(@.name = 'Mozart')]", empty()))
@@ -143,7 +143,7 @@ public void testHamcrestMatcherWithParameterizedJsonPath() throws Exception {
String performerName = "$.performers[%s].name";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/json;charset=UTF-8"))
+ .andExpect(content().mimeType("application/json;charset=UTF-8"))
.andExpect(jsonPath(composerName, 0).value(startsWith("Johann")))
.andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy")))
.andExpect(jsonPath(performerName, 1).value(containsString("di Me")))
View
4 ...a/org/springframework/test/web/client/samples/matchers/XmlContentRequestMatcherTests.java
@@ -95,7 +95,7 @@ public void setup() {
@Test
public void testXmlEqualTo() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(content().xml(PEOPLE_XML))
.andRespond(withSuccess());
@@ -110,7 +110,7 @@ public void testHamcrestNodeMatcher() throws Exception {
nsContext.setBindings(NAMESPACES);
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(content().node(hasXPath("/ns:people/composers/composer[1]", nsContext)))
.andRespond(withSuccess());
View
12 ...t/java/org/springframework/test/web/client/samples/matchers/XpathRequestMatcherTests.java
@@ -97,7 +97,7 @@ public void testExists() throws Exception {
String performer = "/ns:people/performers/performer[%s]";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath(composer, NS, 1).exists())
.andExpect(xpath(composer, NS, 2).exists())
.andExpect(xpath(composer, NS, 3).exists())
@@ -117,7 +117,7 @@ public void testDoesNotExist() throws Exception {
String performer = "/ns:people/performers/performer[%s]";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath(composer, NS, 0).doesNotExist())
.andExpect(xpath(composer, NS, 5).doesNotExist())
.andExpect(xpath(performer, NS, 0).doesNotExist())
@@ -135,7 +135,7 @@ public void testString() throws Exception {
String performerName = "/ns:people/performers/performer[%s]/name";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath(composerName, NS, 1).string("Johann Sebastian Bach"))
.andExpect(xpath(composerName, NS, 2).string("Johannes Brahms"))
.andExpect(xpath(composerName, NS, 3).string("Edvard Grieg"))
@@ -157,7 +157,7 @@ public void testNumber() throws Exception {
String composerDouble = "/ns:people/composers/composer[%s]/someDouble";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath(composerDouble, NS, 1).number(21d))
.andExpect(xpath(composerDouble, NS, 2).number(.0025))
.andExpect(xpath(composerDouble, NS, 3).number(1.6035))
@@ -176,7 +176,7 @@ public void testBoolean() throws Exception {
String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean";
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath(performerBooleanValue, NS, 1).booleanValue(false))
.andExpect(xpath(performerBooleanValue, NS, 2).booleanValue(true))
.andRespond(withSuccess());
@@ -189,7 +189,7 @@ public void testBoolean() throws Exception {
public void testNodeCount() throws Exception {
this.mockServer.expect(requestTo("/composers"))
- .andExpect(content().type("application/xml"))
+ .andExpect(content().mimeType("application/xml"))
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4))
.andExpect(xpath("/ns:people/performers/performer", NS).nodeCount(2))
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(lessThan(5))) // Hamcrest..
View
4 src/test/java/org/springframework/test/web/server/result/ContentResultMatchersTests.java
@@ -28,12 +28,12 @@
@Test
public void typeMatches() throws Exception {
- new ContentResultMatchers().type("application/json;charset=UTF-8").match(getStubMvcResult());
+ new ContentResultMatchers().mimeType("application/json;charset=UTF-8").match(getStubMvcResult());
}
@Test(expected=AssertionError.class)
public void typeNoMatch() throws Exception {
- new ContentResultMatchers().type("text/plain").match(getStubMvcResult());
+ new ContentResultMatchers().mimeType("text/plain").match(getStubMvcResult());
}
@Test
View
4 src/test/java/org/springframework/test/web/server/samples/context/WarRootDirectoryTests.java
@@ -82,7 +82,7 @@ public void tilesDefinitions() throws Exception {
public void resourceRequest() throws Exception {
mockMvc.perform(get("/resources/Spring.js"))
.andExpect(status().isOk())
- .andExpect(content().type("text/javascript"))
+ .andExpect(content().mimeType("text/javascript"))
.andExpect(content().string(containsString("Spring={};")));
}
@@ -92,7 +92,7 @@ public void resourceRequest() throws Exception {
public void resourcesViaDefaultServlet() throws Exception {
mockMvc.perform(get("/unknown/resource"))
.andExpect(status().isOk())
- .andExpect(handler().type(DefaultServletHttpRequestHandler.class))
+ .andExpect(handler().handlerType(DefaultServletHttpRequestHandler.class))
.andExpect(forwardedUrl("default"));
}
View
2 src/test/java/org/springframework/test/web/server/samples/standalone/ResponseBodyTests.java
@@ -41,7 +41,7 @@ public void json() throws Exception {
standaloneSetup(new PersonController()).build()
.perform(get("/person/Lee").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andExpect(content().type(MediaType.APPLICATION_JSON))
+ .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.name").value("Lee"));
}
View
8 ...test/java/org/springframework/test/web/server/samples/standalone/ViewResolutionTests.java
@@ -75,7 +75,7 @@ public void testJsonOnly() throws Exception {
.setSingleView(new MappingJacksonJsonView()).build()
.perform(get("/person/Corea"))
.andExpect(status().isOk())
- .andExpect(content().type(MediaType.APPLICATION_JSON))
+ .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Corea"));
}
@@ -89,7 +89,7 @@ public void testXmlOnly() throws Exception {
.setSingleView(new MarshallingView(marshaller)).build()
.perform(get("/person/Corea"))
.andExpect(status().isOk())
- .andExpect(content().type(MediaType.APPLICATION_XML))
+ .andExpect(content().mimeType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
@@ -120,12 +120,12 @@ public void testContentNegotiation() throws Exception {
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
- .andExpect(content().type(MediaType.APPLICATION_JSON))
+ .andExpect(content().mimeType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.person.name").value("Corea"));
mockMvc.perform(get("/person/Corea").accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk())
- .andExpect(content().type(MediaType.APPLICATION_XML))
+ .andExpect(content().mimeType(MediaType.APPLICATION_XML))
.andExpect(xpath("/person/name/text()").string(equalTo("Corea")));
}
View
8 ...ramework/test/web/server/samples/standalone/resultmatchers/ContentResultMatcherTests.java
@@ -52,12 +52,12 @@ public void setup() {
@Test
public void testContentType() throws Exception {
this.mockMvc.perform(get("/handle"))
- .andExpect(content().type(MediaType.TEXT_PLAIN))
- .andExpect(content().type("text/plain"));
+ .andExpect(content().mimeType(MediaType.TEXT_PLAIN))
+ .andExpect(content().mimeType("text/plain"));
this.mockMvc.perform(get("/handleUtf8"))
- .andExpect(content().type(MediaType.valueOf("text/plain;charset=UTF-8")))
- .andExpect(content().type("text/plain;charset=UTF-8"));
+ .andExpect(content().mimeType(MediaType.valueOf("text/plain;charset=UTF-8")))
+ .andExpect(content().mimeType("text/plain;charset=UTF-8"));
}
@Test
View
2 ...ramework/test/web/server/samples/standalone/resultmatchers/HandlerResultMatcherTests.java
@@ -50,7 +50,7 @@ public void setup() {
@Test
public void testHandlerType() throws Exception {
- this.mockMvc.perform(get("/")).andExpect(handler().type(SimpleController.class));
+ this.mockMvc.perform(get("/")).andExpect(handler().handlerType(SimpleController.class));
}
@Test

0 comments on commit d2510b7

Please sign in to comment.