1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import static org .springframework .test .util .AssertionErrors .*;
29
29
30
30
/**
31
- * Static, factory methods for {@link ResultMatcher}-based result actions.
31
+ * Static factory methods for {@link ResultMatcher}-based result actions.
32
32
*
33
- * <p><strong>Eclipse users:</strong> consider adding this class as a Java editor
34
- * favorite. To navigate, open the Preferences and type "favorites".
33
+ * <h3>Eclipse Users</h3>
34
+ * <p>Consider adding this class as a Java editor favorite. To navigate to
35
+ * this setting, open the Preferences and type "favorites".
35
36
*
36
37
* @author Rossen Stoyanchev
37
38
* @author Brian Clozel
39
+ * @author Sam Brannen
38
40
* @since 3.2
39
41
*/
40
42
public abstract class MockMvcResultMatchers {
41
43
42
44
private static final AntPathMatcher pathMatcher = new AntPathMatcher ();
43
45
44
46
45
- private MockMvcResultMatchers () {
46
- }
47
-
48
47
/**
49
48
* Access to request-related assertions.
50
49
*/
@@ -82,12 +81,11 @@ public static FlashAttributeResultMatchers flash() {
82
81
83
82
/**
84
83
* Asserts the request was forwarded to the given URL.
85
- * This methods accepts only exact matches.
84
+ * <p> This methods accepts only exact matches.
86
85
* @param expectedUrl the exact URL expected
87
86
*/
88
87
public static ResultMatcher forwardedUrl (final String expectedUrl ) {
89
88
return new ResultMatcher () {
90
-
91
89
@ Override
92
90
public void match (MvcResult result ) {
93
91
assertEquals ("Forwarded URL" , expectedUrl , result .getResponse ().getForwardedUrl ());
@@ -97,14 +95,14 @@ public void match(MvcResult result) {
97
95
98
96
/**
99
97
* Asserts the request was forwarded to the given URL.
100
- * This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
98
+ * <p>This methods accepts {@link org.springframework.util.AntPathMatcher}
99
+ * expressions.
101
100
* @param urlPattern an AntPath expression to match against
102
- * @see org.springframework.util.AntPathMatcher
103
101
* @since 4.0
102
+ * @see org.springframework.util.AntPathMatcher
104
103
*/
105
104
public static ResultMatcher forwardedUrlPattern (final String urlPattern ) {
106
105
return new ResultMatcher () {
107
-
108
106
@ Override
109
107
public void match (MvcResult result ) {
110
108
assertTrue ("AntPath expression" , pathMatcher .isPattern (urlPattern ));
@@ -116,12 +114,11 @@ public void match(MvcResult result) {
116
114
117
115
/**
118
116
* Asserts the request was redirected to the given URL.
119
- * This methods accepts only exact matches.
117
+ * <p> This methods accepts only exact matches.
120
118
* @param expectedUrl the exact URL expected
121
119
*/
122
120
public static ResultMatcher redirectedUrl (final String expectedUrl ) {
123
121
return new ResultMatcher () {
124
-
125
122
@ Override
126
123
public void match (MvcResult result ) {
127
124
assertEquals ("Redirected URL" , expectedUrl , result .getResponse ().getRedirectedUrl ());
@@ -131,14 +128,14 @@ public void match(MvcResult result) {
131
128
132
129
/**
133
130
* Asserts the request was redirected to the given URL.
134
- * This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
131
+ * <p>This method accepts {@link org.springframework.util.AntPathMatcher}
132
+ * expressions.
135
133
* @param expectedUrl an AntPath expression to match against
136
134
* @see org.springframework.util.AntPathMatcher
137
135
* @since 4.0
138
136
*/
139
137
public static ResultMatcher redirectedUrlPattern (final String expectedUrl ) {
140
138
return new ResultMatcher () {
141
-
142
139
@ Override
143
140
public void match (MvcResult result ) {
144
141
assertTrue ("AntPath expression" ,pathMatcher .isPattern (expectedUrl ));
@@ -170,25 +167,24 @@ public static ContentResultMatchers content() {
170
167
}
171
168
172
169
/**
173
- * Access to response body assertions using a <a
174
- * href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to
175
- * inspect a specific subset of the body. The JSON path expression can be a
176
- * parameterized string using formatting specifiers as defined in
170
+ * Access to response body assertions using a
171
+ * <a href="https://github.com/jayway/JsonPath">JsonPath</a> expression
172
+ * to inspect a specific subset of the body.
173
+ * <p>The JSON path expression can be a parameterized string using
174
+ * formatting specifiers as defined in
177
175
* {@link String#format(String, Object...)}.
178
- *
179
- * @param expression the JSON path optionally parameterized with arguments
176
+ * @param expression the JSON path expression, optionally parameterized with arguments
180
177
* @param args arguments to parameterize the JSON path expression with
181
178
*/
182
179
public static JsonPathResultMatchers jsonPath (String expression , Object ... args ) {
183
180
return new JsonPathResultMatchers (expression , args );
184
181
}
185
182
186
183
/**
187
- * Access to response body assertions using a <a
188
- * href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to
189
- * inspect a specific subset of the body and a Hamcrest match for asserting
190
- * the value found at the JSON path.
191
- *
184
+ * Access to response body assertions using a
185
+ * <a href="https://github.com/jayway/JsonPath">JsonPath</a> expression
186
+ * to inspect a specific subset of the body and a Hamcrest matcher for
187
+ * asserting the value found at the JSON path.
192
188
* @param expression the JSON path expression
193
189
* @param matcher a matcher for the value expected at the JSON path
194
190
*/
@@ -197,25 +193,23 @@ public static <T> ResultMatcher jsonPath(String expression, Matcher<T> matcher)
197
193
}
198
194
199
195
/**
200
- * Access to response body assertions using an XPath to inspect a specific
201
- * subset of the body. The XPath expression can be a parameterized string
202
- * using formatting specifiers as defined in
203
- * {@link String#format(String, Object...)}.
204
- *
205
- * @param expression the XPath optionally parameterized with arguments
196
+ * Access to response body assertions using an XPath expression to
197
+ * inspect a specific subset of the body.
198
+ * <p>The XPath expression can be a parameterized string using formatting
199
+ * specifiers as defined in {@link String#format(String, Object...)}.
200
+ * @param expression the XPath expression, optionally parameterized with arguments
206
201
* @param args arguments to parameterize the XPath expression with
207
202
*/
208
203
public static XpathResultMatchers xpath (String expression , Object ... args ) throws XPathExpressionException {
209
204
return new XpathResultMatchers (expression , null , args );
210
205
}
211
206
212
207
/**
213
- * Access to response body assertions using an XPath to inspect a specific
214
- * subset of the body. The XPath expression can be a parameterized string
215
- * using formatting specifiers as defined in
216
- * {@link String#format(String, Object...)}.
217
- *
218
- * @param expression the XPath optionally parameterized with arguments
208
+ * Access to response body assertions using an XPath expression to
209
+ * inspect a specific subset of the body.
210
+ * <p>The XPath expression can be a parameterized string using formatting
211
+ * specifiers as defined in {@link String#format(String, Object...)}.
212
+ * @param expression the XPath expression, optionally parameterized with arguments
219
213
* @param namespaces namespaces referenced in the XPath expression
220
214
* @param args arguments to parameterize the XPath expression with
221
215
*/
0 commit comments