Skip to content

Commit c9bb059

Browse files
committed
Polish
Issue: SPR-10789
1 parent e04a756 commit c9bb059

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

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

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

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

19-
import static org.springframework.test.util.AssertionErrors.assertEquals;
20-
import static org.springframework.test.util.AssertionErrors.assertTrue;
21-
2219
import java.util.Map;
2320

2421
import javax.xml.xpath.XPathExpressionException;
@@ -28,6 +25,8 @@
2825
import org.springframework.test.web.servlet.ResultMatcher;
2926
import org.springframework.util.AntPathMatcher;
3027

28+
import static org.springframework.test.util.AssertionErrors.*;
29+
3130
/**
3231
* Static, factory methods for {@link ResultMatcher}-based result actions.
3332
*
@@ -40,6 +39,8 @@
4039
*/
4140
public abstract class MockMvcResultMatchers {
4241

42+
private static final AntPathMatcher pathMatcher = new AntPathMatcher();
43+
4344

4445
private MockMvcResultMatchers() {
4546
}
@@ -86,6 +87,7 @@ public static FlashAttributeResultMatchers flash() {
8687
*/
8788
public static ResultMatcher forwardedUrl(final String expectedUrl) {
8889
return new ResultMatcher() {
90+
8991
@Override
9092
public void match(MvcResult result) {
9193
assertEquals("Forwarded URL", expectedUrl, result.getResponse().getForwardedUrl());
@@ -97,23 +99,18 @@ public void match(MvcResult result) {
9799
* Asserts the request was forwarded to the given URL.
98100
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
99101
*
100-
* <p>When trying to match against "?" or "*" exactly, those characters
101-
* should be escaped (e.g. "\\?" and "\\*")
102-
*
103-
* @param expectedUrl an AntPath expression to match against
102+
* @param urlPattern an AntPath expression to match against
104103
* @see org.springframework.util.AntPathMatcher
105104
* @since 4.0
106105
*/
107-
public static ResultMatcher forwardedUrlPattern(final String expectedUrl) {
106+
public static ResultMatcher forwardedUrlPattern(final String urlPattern) {
108107
return new ResultMatcher() {
109108

110-
private final AntPathMatcher pathMatcher = new AntPathMatcher();
111-
112109
@Override
113110
public void match(MvcResult result) {
114-
assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl));
115-
assertTrue("Forwarded URL",
116-
pathMatcher.match(expectedUrl, result.getResponse().getForwardedUrl()));
111+
assertTrue("AntPath expression", pathMatcher.isPattern(urlPattern));
112+
assertTrue("Forwarded URL does not match the expected URL pattern",
113+
pathMatcher.match(urlPattern, result.getResponse().getForwardedUrl()));
117114
}
118115
};
119116
}
@@ -125,6 +122,7 @@ public void match(MvcResult result) {
125122
*/
126123
public static ResultMatcher redirectedUrl(final String expectedUrl) {
127124
return new ResultMatcher() {
125+
128126
@Override
129127
public void match(MvcResult result) {
130128
assertEquals("Redirected URL", expectedUrl, result.getResponse().getRedirectedUrl());
@@ -136,18 +134,13 @@ public void match(MvcResult result) {
136134
* Asserts the request was redirected to the given URL.
137135
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
138136
*
139-
* <p>When trying to match against "?" or "*" exactly, those characters
140-
* should be escaped (e.g. "\\?" and "\\*")
141-
*
142137
* @param expectedUrl an AntPath expression to match against
143138
* @see org.springframework.util.AntPathMatcher
144139
* @since 4.0
145140
*/
146141
public static ResultMatcher redirectedUrlPattern(final String expectedUrl) {
147142
return new ResultMatcher() {
148143

149-
private final AntPathMatcher pathMatcher = new AntPathMatcher();
150-
151144
@Override
152145
public void match(MvcResult result) {
153146
assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl));

0 commit comments

Comments
 (0)