Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
Issue: SPR-10789
  • Loading branch information
rstoyanchev committed Oct 8, 2013
1 parent e04a756 commit c9bb059
Showing 1 changed file with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +25,8 @@
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.
*
Expand All @@ -40,6 +39,8 @@
*/
public abstract class MockMvcResultMatchers {

private static final AntPathMatcher pathMatcher = new AntPathMatcher();


private MockMvcResultMatchers() {
}
Expand Down Expand Up @@ -86,6 +87,7 @@ public static FlashAttributeResultMatchers flash() {
*/
public static ResultMatcher forwardedUrl(final String expectedUrl) {
return new ResultMatcher() {

@Override
public void match(MvcResult result) {
assertEquals("Forwarded URL", expectedUrl, result.getResponse().getForwardedUrl());
Expand All @@ -97,23 +99,18 @@ public void match(MvcResult result) {
* Asserts the request was forwarded to the given URL.
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
*
* <p>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()));
}
};
}
Expand All @@ -125,6 +122,7 @@ public void match(MvcResult result) {
*/
public static ResultMatcher redirectedUrl(final String expectedUrl) {
return new ResultMatcher() {

@Override
public void match(MvcResult result) {
assertEquals("Redirected URL", expectedUrl, result.getResponse().getRedirectedUrl());
Expand All @@ -136,18 +134,13 @@ public void match(MvcResult result) {
* Asserts the request was redirected to the given URL.
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
*
* <p>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
*/
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));
Expand Down

0 comments on commit c9bb059

Please sign in to comment.