From c9bb0594f3f3604c6a5d6640ccdab903fb6860d5 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Tue, 8 Oct 2013 15:57:59 -0400 Subject: [PATCH] Polish Issue: SPR-10789 --- .../servlet/result/MockMvcResultMatchers.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java b/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java index 3532bc71d2..90ca60a9c4 100644 --- a/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java +++ b/spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java @@ -16,9 +16,6 @@ package org.springframework.test.web.servlet.result; -import static org.springframework.test.util.AssertionErrors.assertEquals; -import static org.springframework.test.util.AssertionErrors.assertTrue; - import java.util.Map; import javax.xml.xpath.XPathExpressionException; @@ -28,6 +25,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.util.AntPathMatcher; +import static org.springframework.test.util.AssertionErrors.*; + /** * Static, factory methods for {@link ResultMatcher}-based result actions. * @@ -40,6 +39,8 @@ import org.springframework.util.AntPathMatcher; */ public abstract class MockMvcResultMatchers { + private static final AntPathMatcher pathMatcher = new AntPathMatcher(); + private MockMvcResultMatchers() { } @@ -86,6 +87,7 @@ public abstract class MockMvcResultMatchers { */ public static ResultMatcher forwardedUrl(final String expectedUrl) { return new ResultMatcher() { + @Override public void match(MvcResult result) { assertEquals("Forwarded URL", expectedUrl, result.getResponse().getForwardedUrl()); @@ -97,23 +99,18 @@ public abstract class MockMvcResultMatchers { * Asserts the request was forwarded to the given URL. * This methods accepts {@link org.springframework.util.AntPathMatcher} expressions. * - *

When trying to match against "?" or "*" exactly, those characters - * should be escaped (e.g. "\\?" and "\\*") - * - * @param expectedUrl an AntPath expression to match against + * @param urlPattern an AntPath expression to match against * @see org.springframework.util.AntPathMatcher * @since 4.0 */ - public static ResultMatcher forwardedUrlPattern(final String expectedUrl) { + public static ResultMatcher forwardedUrlPattern(final String urlPattern) { return new ResultMatcher() { - private final AntPathMatcher pathMatcher = new AntPathMatcher(); - @Override public void match(MvcResult result) { - assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl)); - assertTrue("Forwarded URL", - pathMatcher.match(expectedUrl, result.getResponse().getForwardedUrl())); + assertTrue("AntPath expression", pathMatcher.isPattern(urlPattern)); + assertTrue("Forwarded URL does not match the expected URL pattern", + pathMatcher.match(urlPattern, result.getResponse().getForwardedUrl())); } }; } @@ -125,6 +122,7 @@ public abstract class MockMvcResultMatchers { */ public static ResultMatcher redirectedUrl(final String expectedUrl) { return new ResultMatcher() { + @Override public void match(MvcResult result) { assertEquals("Redirected URL", expectedUrl, result.getResponse().getRedirectedUrl()); @@ -136,9 +134,6 @@ public abstract class MockMvcResultMatchers { * Asserts the request was redirected to the given URL. * This methods accepts {@link org.springframework.util.AntPathMatcher} expressions. * - *

When trying to match against "?" or "*" exactly, those characters - * should be escaped (e.g. "\\?" and "\\*") - * * @param expectedUrl an AntPath expression to match against * @see org.springframework.util.AntPathMatcher * @since 4.0 @@ -146,8 +141,6 @@ public abstract class MockMvcResultMatchers { public static ResultMatcher redirectedUrlPattern(final String expectedUrl) { return new ResultMatcher() { - private final AntPathMatcher pathMatcher = new AntPathMatcher(); - @Override public void match(MvcResult result) { assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl));