Skip to content

Commit 6a59d00

Browse files
committed
Fix references and typos in Spring MVC Test Javadoc
This commit fixes numerous references to 'legacy' packages within the Javadoc for the Spring MVC Test framework. In addition, this commit improves examples in Javadoc, adds links to related classes where appropriate, and removes unnecessary imports for types that are only referenced within documentation. Issue: SPR-13284
1 parent 8de7848 commit 6a59d00

File tree

8 files changed

+89
-71
lines changed

8 files changed

+89
-71
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@
3333
/**
3434
* <strong>Main entry point for server-side Spring MVC test support.</strong>
3535
*
36-
* <p>Below is an example:
36+
* <h3>Example</h3>
3737
*
3838
* <pre class="code">
39-
* static imports:
40-
* MockMvcBuilders.*, MockMvcRequestBuilders.*, MockMvcResultMatchers.*
39+
* import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
40+
* import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
41+
* import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
42+
*
43+
* // ...
4144
*
4245
* WebApplicationContext wac = ...;
4346
*

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,10 +17,10 @@
1717
package org.springframework.test.web.servlet;
1818

1919
/**
20-
* Builds a {@link MockMvc}.
20+
* Builds a {@link MockMvc} instance.
2121
*
22-
* <p>See static, factory methods in
23-
* {@code org.springframework.test.web.server.setup.MockMvcBuilders}.
22+
* <p>See static factory methods in
23+
* {@link org.springframework.test.web.servlet.setup.MockMvcBuilders MockMvcBuilders}.
2424
*
2525
* @author Rossen Stoyanchev
2626
* @since 3.2

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.test.web.servlet;
1718

1819
import javax.servlet.ServletContext;
@@ -22,8 +23,8 @@
2223
/**
2324
* Builds a {@link MockHttpServletRequest}.
2425
*
25-
* <p>See static, factory methods in
26-
* {@code org.springframework.test.web.server.request.MockMvcRequestBuilders}.
26+
* <p>See static factory methods in
27+
* {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders MockMvcRequestBuilders}.
2728
*
2829
* @author Arjen Poutsma
2930
* @author Rossen Stoyanchev

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,16 +21,18 @@
2121
* request.
2222
*
2323
* <p>See static factory methods in
24-
* {@code org.springframework.test.web.servlet.result.MockMvcResultMatchers}
25-
* {@code org.springframework.test.web.servlet.result.MockMvcResultHandlers}
24+
* {@link org.springframework.test.web.servlet.result.MockMvcResultMatchers} and
25+
* {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers}.
2626
*
2727
* @author Rossen Stoyanchev
2828
* @since 3.2
2929
*/
3030
public interface ResultActions {
3131

3232
/**
33-
* Provide an expectation. For example:
33+
* Perform an expectation.
34+
*
35+
* <h4>Example</h4>
3436
* <pre class="code">
3537
* static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
3638
*
@@ -51,7 +53,9 @@ public interface ResultActions {
5153
ResultActions andExpect(ResultMatcher matcher) throws Exception;
5254

5355
/**
54-
* Provide a general action. For example:
56+
* Perform a general action.
57+
*
58+
* <h4>Example</h4>
5559
* <pre class="code">
5660
* static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
5761
*

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,27 +17,37 @@
1717
package org.springframework.test.web.servlet;
1818

1919
/**
20-
* Executes a generic action (e.g. printing debug information) on the result of
21-
* an executed request.
20+
* A {@code ResultHandler} performs a generic action on the result of an
21+
* executed request &mdash; for example, printing debug information.
2222
*
2323
* <p>See static factory methods in
24-
* {@code org.springframework.test.web.server.result.MockMvcResultHandlers}.
24+
* {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers
25+
* MockMvcResultHandlers}.
2526
*
26-
* <p>Example:
27+
* <h3>Example</h3>
2728
*
2829
* <pre class="code">
29-
* static imports: MockMvcRequestBuilders.*, MockMvcResultHandlers.*
30+
* import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
31+
* import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.*;
32+
* import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
33+
*
34+
* // ...
35+
*
36+
* WebApplicationContext wac = ...;
37+
*
38+
* MockMvc mockMvc = webAppContextSetup(wac).build();
3039
*
3140
* mockMvc.perform(get("/form")).andDo(print());
3241
* </pre>
3342
*
3443
* @author Rossen Stoyanchev
44+
* @author Sam Brannen
3545
* @since 3.2
3646
*/
3747
public interface ResultHandler {
3848

3949
/**
40-
* Apply the action on the given result.
50+
* Perform an action on the given result.
4151
*
4252
* @param result the result of the executed request
4353
* @throws Exception if a failure occurs

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,22 +17,33 @@
1717
package org.springframework.test.web.servlet;
1818

1919
/**
20-
* Matches the result of an executed request against some expectation.
20+
* A {@code ResultMatcher} matches the result of an executed request against
21+
* some expectation.
2122
*
2223
* <p>See static factory methods in
23-
* {@code org.springframework.test.web.server.result.MockMvcResultMatchers}.
24+
* {@link org.springframework.test.web.servlet.result.MockMvcResultMatchers
25+
* MockMvcResultMatchers}.
2426
*
25-
* <p>Example:
27+
* <h3>Example Using Status and Content Result Matchers</h3>
2628
*
2729
* <pre class="code">
28-
* static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
30+
* import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
31+
* import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
32+
* import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
33+
*
34+
* // ...
35+
*
36+
* WebApplicationContext wac = ...;
37+
*
38+
* MockMvc mockMvc = webAppContextSetup(wac).build();
2939
*
3040
* mockMvc.perform(get("/form"))
31-
* .andExpect(status.isOk())
41+
* .andExpect(status().isOk())
3242
* .andExpect(content().mimeType(MediaType.APPLICATION_JSON));
3343
* </pre>
3444
*
3545
* @author Rossen Stoyanchev
46+
* @author Sam Brannen
3647
* @since 3.2
3748
*/
3849
public interface ResultMatcher {

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.springframework.http.HttpMethod;
2323
import org.springframework.mock.web.MockHttpServletRequest;
24-
import org.springframework.mock.web.MockMultipartHttpServletRequest;
2524
import org.springframework.test.web.servlet.MvcResult;
2625
import org.springframework.test.web.servlet.RequestBuilder;
2726

@@ -33,10 +32,6 @@
3332
* {@link org.springframework.mock.web.MockServletContext MockServletContext}
3433
* that was created by the Spring TestContext Framework.
3534
*
36-
* <p>Methods in this class that return a {@link MockHttpServletRequestBuilder}
37-
* will reuse a {@link MockHttpServletRequest} that was created by the Spring
38-
* TestContext Framework.
39-
*
4035
* <h3>Eclipse Users</h3>
4136
* <p>Consider adding this class as a Java editor favorite. To navigate to
4237
* this setting, open the Preferences and type "favorites".
@@ -199,11 +194,6 @@ public static MockHttpServletRequestBuilder request(HttpMethod httpMethod, URI u
199194

200195
/**
201196
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
202-
* <p>In contrast to methods in this class that return a
203-
* {@link MockHttpServletRequestBuilder}, the builder returned by this
204-
* method will always create a new {@link MockMultipartHttpServletRequest}
205-
* that is <em>not</em> associated with a mock request created by the
206-
* Spring TestContext Framework.
207197
* @param urlTemplate a URL template; the resulting URL will be encoded
208198
* @param urlVariables zero or more URL variables
209199
*/
@@ -213,11 +203,6 @@ public static MockMultipartHttpServletRequestBuilder fileUpload(String urlTempla
213203

214204
/**
215205
* Create a {@link MockMultipartHttpServletRequestBuilder} for a multipart request.
216-
* <p>In contrast to methods in this class that return a
217-
* {@link MockHttpServletRequestBuilder}, the builder returned by this
218-
* method will always create a new {@link MockMultipartHttpServletRequest}
219-
* that is <em>not</em> associated with a mock request created by the
220-
* Spring TestContext Framework.
221206
* @param uri the URL
222207
* @since 4.0.3
223208
*/
@@ -228,7 +213,7 @@ public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri) {
228213
/**
229214
* Create a {@link RequestBuilder} for an async dispatch from the
230215
* {@link MvcResult} of the request that started async processing.
231-
* <p>Usage involves performing one request first that starts async processing:
216+
* <p>Usage involves performing a request that starts async processing first:
232217
* <pre class="code">
233218
* MvcResult mvcResult = this.mockMvc.perform(get("/1"))
234219
* .andExpect(request().asyncStarted())

spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcBuilders.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,56 +16,60 @@
1616

1717
package org.springframework.test.web.servlet.setup;
1818

19-
import javax.servlet.ServletContext;
20-
21-
import org.springframework.stereotype.Controller;
2219
import org.springframework.test.web.servlet.MockMvc;
2320
import org.springframework.test.web.servlet.MockMvcBuilder;
2421
import org.springframework.web.context.WebApplicationContext;
25-
import org.springframework.web.servlet.DispatcherServlet;
2622

2723
/**
28-
* The main class to import to access all available {@link MockMvcBuilder}s.
24+
* The main class to import in order to access all available {@link MockMvcBuilder}s.
2925
*
30-
* <p><strong>Eclipse users:</strong> consider adding this class as a Java editor
31-
* favorite. To navigate, open the Preferences and type "favorites".
26+
* <h3>Eclipse Users</h3>
27+
* <p>Consider adding this class as a Java editor favorite. To navigate to
28+
* this setting, open the Preferences and type "favorites".
3229
*
3330
* @author Rossen Stoyanchev
31+
* @author Sam Brannen
3432
* @since 3.2
33+
* @see #webAppContextSetup(WebApplicationContext)
34+
* @see #standaloneSetup(Object...)
3535
*/
3636
public class MockMvcBuilders {
3737

3838
/**
39-
* Build a {@link MockMvc} using the given, fully initialized, i.e.
40-
* refreshed, {@link WebApplicationContext}. The {@link DispatcherServlet}
41-
* will use the context to discover Spring MVC infrastructure and
42-
* application controllers in it. The context must have been configured with
43-
* a {@link ServletContext}.
39+
* Build a {@link MockMvc} instance using the given, fully initialized
40+
* (i.e., <em>refreshed</em>) {@link WebApplicationContext}.
41+
* <p>The {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet}
42+
* will use the context to discover Spring MVC infrastructure and application
43+
* controllers in it. The context must have been configured with a
44+
* {@link javax.servlet.ServletContext ServletContext}.
4445
*/
4546
public static DefaultMockMvcBuilder webAppContextSetup(WebApplicationContext context) {
4647
return new DefaultMockMvcBuilder(context);
4748
}
4849

4950
/**
50-
* Build a {@link MockMvc} by registering one or more {@code @Controller}'s
51-
* instances and configuring Spring MVC infrastructure programmatically.
52-
* This allows full control over the instantiation and initialization of
53-
* controllers, and their dependencies, similar to plain unit tests while
51+
* Build a {@link MockMvc} instance by registering one or more
52+
* {@code @Controller} instances and configuring Spring MVC infrastructure
53+
* programmatically.
54+
*
55+
* <p>This allows full control over the instantiation and initialization of
56+
* controllers and their dependencies, similar to plain unit tests while
5457
* also making it possible to test one controller at a time.
5558
*
56-
* <p>When this option is used, the minimum infrastructure required by the
57-
* {@link DispatcherServlet} to serve requests with annotated controllers is
58-
* automatically created, and can be customized, resulting in configuration
59-
* that is equivalent to what the MVC Java configuration provides except
60-
* using builder style methods.
59+
* <p>When this builder is used, the minimum infrastructure required by the
60+
* {@link org.springframework.web.servlet.DispatcherServlet DispatcherServlet}
61+
* to serve requests with annotated controllers is created automatically
62+
* and can be customized, resulting in configuration that is equivalent to
63+
* what MVC Java configuration provides except using builder-style methods.
6164
*
6265
* <p>If the Spring MVC configuration of an application is relatively
63-
* straight-forward, for example when using the MVC namespace or the MVC
64-
* Java config, then using this builder might be a good option for testing
65-
* a majority of controllers. A much smaller number of tests can be used
66-
* to focus on testing and verifying the actual Spring MVC configuration.
66+
* straight-forward &mdash; for example, when using the MVC namespace in
67+
* XML or MVC Java config &mdash; then using this builder might be a good
68+
* option for testing a majority of controllers. In such cases, a much
69+
* smaller number of tests can be used to focus on testing and verifying
70+
* the actual Spring MVC configuration.
6771
*
68-
* @param controllers one or more {@link Controller @Controller}'s to test
72+
* @param controllers one or more {@code @Controller} instances to test
6973
*/
7074
public static StandaloneMockMvcBuilder standaloneSetup(Object... controllers) {
7175
return new StandaloneMockMvcBuilder(controllers);

0 commit comments

Comments
 (0)