1616
1717package 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-
2219import java .util .Map ;
2320
2421import javax .xml .xpath .XPathExpressionException ;
2825import org .springframework .test .web .servlet .ResultMatcher ;
2926import 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 *
4039 */
4140public 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