Deprecated MatcherAssertionErrors in favor of the original org.hamcrest.MatcherAssert (v1.3)

As of JUnit 4.9 / Hamcrest 1.3, there is no real need for a custom copy of that class anymore.
This commit is contained in:
Juergen Hoeller
2015-03-25 00:04:47 +01:00
parent e81862eed6
commit 4e1af7d195
21 changed files with 107 additions and 144 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,8 +28,8 @@ import org.hamcrest.Matcher;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* A helper class for applying assertions via JSON path expressions.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,17 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.util;
import java.lang.reflect.Method;
package org.springframework.test.util;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.StringDescription;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
/**
* A replacement of {@link org.hamcrest.MatcherAssert} that removes the need to
* depend on "hamcrest-all" when using Hamcrest 1.1 and also maintains backward
@@ -32,19 +28,14 @@ import org.springframework.util.ReflectionUtils;
* @author Rossen Stoyanchev
* @author Sam Brannen
* @since 3.2
* @deprecated as of Spring 4.2, in favor of the original
* {@link org.hamcrest.MatcherAssert} class with JUnit 4.9 / Hamcrest 1.3
*/
@Deprecated
public abstract class MatcherAssertionErrors {
private static final Method describeMismatchMethod =
ClassUtils.getMethodIfAvailable(Matcher.class, "describeMismatch", Object.class, Description.class);
private MatcherAssertionErrors() {
}
/**
* Asserts that the given matcher matches the actual value.
*
* Assert that the given matcher matches the actual value.
* @param <T> the static type accepted by the matcher
* @param actual the value to match against
* @param matcher the matcher
@@ -54,8 +45,7 @@ public abstract class MatcherAssertionErrors {
}
/**
* Asserts that the given matcher matches the actual value.
*
* Assert that the given matcher matches the actual value.
* @param <T> the static type accepted by the matcher
* @param reason additional information about the error
* @param actual the value to match against
@@ -67,16 +57,8 @@ public abstract class MatcherAssertionErrors {
description.appendText(reason);
description.appendText("\nExpected: ");
description.appendDescriptionOf(matcher);
if (describeMismatchMethod != null) {
description.appendText("\n but: ");
// matcher.describeMismatch(actual, description);
ReflectionUtils.invokeMethod(describeMismatchMethod, matcher, actual, description);
}
else {
description.appendText("\n got: ");
description.appendValue(actual);
description.appendText("\n");
}
description.appendText("\n but: ");
matcher.describeMismatch(actual, description);
throw new AssertionError(description.toString());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import static org.springframework.test.util.MatcherAssertionErrors.*;
import static org.hamcrest.MatcherAssert.*;
/**
* A helper class for assertions on XML content.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,8 +37,8 @@ import org.xml.sax.InputSource;
import org.springframework.util.CollectionUtils;
import org.springframework.util.xml.SimpleNamespaceContext;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* A helper class for applying assertions via XPath expressions.
@@ -56,8 +56,7 @@ public class XpathExpectationsHelper {
/**
* Class constructor.
*
* XpathExpectationsHelper constructor.
* @param expression the XPath expression
* @param namespaces XML namespaces referenced in the XPath expression, or {@code null}
* @param args arguments to parameterize the XPath expression with using the
@@ -72,6 +71,7 @@ public class XpathExpectationsHelper {
this.hasNamespaces = !CollectionUtils.isEmpty(namespaces);
}
private XPathExpression compileXpathExpression(String expression, Map<String, String> namespaces)
throws XPathExpressionException {
@@ -83,7 +83,7 @@ public class XpathExpectationsHelper {
}
/**
* @return the compiled XPath expression.
* Return the compiled XPath expression.
*/
protected XPathExpression getXpathExpression() {
return this.xpathExpression;
@@ -101,7 +101,6 @@ public class XpathExpectationsHelper {
/**
* Parse the given XML content to a {@link Document}.
*
* @param xml the content to parse
* @return the parsed document
* @throws Exception in case of errors
@@ -111,8 +110,7 @@ public class XpathExpectationsHelper {
factory.setNamespaceAware(this.hasNamespaces);
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
InputSource inputSource = new InputSource(new StringReader(xml));
Document document = documentBuilder.parse(inputSource);
return document;
return documentBuilder.parse(inputSource);
}
/**
@@ -149,7 +147,6 @@ public class XpathExpectationsHelper {
/**
* Apply the XPath expression and assert the resulting content with the
* given Hamcrest matcher.
*
* @throws Exception if content parsing or expression evaluation fails
*/
public void assertNodeCount(String content, Matcher<Integer> matcher) throws Exception {
@@ -171,7 +168,6 @@ public class XpathExpectationsHelper {
/**
* Apply the XPath expression and assert the resulting content with the
* given Hamcrest matcher.
*
* @throws Exception if content parsing or expression evaluation fails
*/
public void assertString(String content, Matcher<? super String> matcher) throws Exception {
@@ -193,7 +189,6 @@ public class XpathExpectationsHelper {
/**
* Apply the XPath expression and assert the resulting content with the
* given Hamcrest matcher.
*
* @throws Exception if content parsing or expression evaluation fails
*/
public void assertNumber(String content, Matcher<? super Double> matcher) throws Exception {
@@ -222,4 +217,4 @@ public class XpathExpectationsHelper {
assertEquals("XPath " + this.expression, expectedValue, Boolean.parseBoolean(actual));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.client.match;
import java.io.IOException;
@@ -28,8 +29,8 @@ import org.springframework.mock.http.client.MockClientHttpRequest;
import org.springframework.test.util.XmlExpectationsHelper;
import org.springframework.test.web.client.RequestMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for request content {@code RequestMatcher}'s. An instance of this

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.client.match;
import java.io.IOException;
@@ -31,14 +32,14 @@ import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.RequestMatcher;
import org.springframework.util.Assert;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Static, factory methods for {@link RequestMatcher} classes. Typically used to
* provide input for {@link MockRestServiceServer#expect(RequestMatcher)}.
*
* <p><strong>Eclipse users:</strong> consider adding this class as a Java editor
* <p><strong>Eclipse users:</strong> Consider adding this class as a Java editor
* favorite. To navigate, open the Preferences and type "favorites".
*
* @author Craig Walls
@@ -47,13 +48,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public abstract class MockRestRequestMatchers {
/**
* Private class constructor.
*/
private MockRestRequestMatchers() {
}
/**
* Match to any request.
*/
@@ -67,7 +61,6 @@ public abstract class MockRestRequestMatchers {
/**
* Assert the request URI string with the given matcher.
*
* @param matcher String matcher for the expected URI
* @return the request matcher
*/
@@ -83,7 +76,6 @@ public abstract class MockRestRequestMatchers {
/**
* Assert the request URI string.
*
* @param expectedUri the expected URI
* @return the request matcher
*/
@@ -99,7 +91,6 @@ public abstract class MockRestRequestMatchers {
/**
* Assert the {@link HttpMethod} of the request.
*
* @param method the HTTP method
* @return the request matcher
*/
@@ -115,7 +106,6 @@ public abstract class MockRestRequestMatchers {
/**
* Expect a request to the given URI.
*
* @param uri the expected URI
* @return the request matcher
*/
@@ -181,7 +171,6 @@ public abstract class MockRestRequestMatchers {
* inspect a specific subset of the body. The JSON path expression can be a
* parameterized string using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the JSON path optionally parameterized with arguments
* @param args arguments to parameterize the JSON path expression with
*/
@@ -194,7 +183,6 @@ public abstract class MockRestRequestMatchers {
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to
* inspect a specific subset of the body and a Hamcrest match for asserting
* the value found at the JSON path.
*
* @param expression the JSON path expression
* @param matcher a matcher for the value expected at the JSON path
*/
@@ -207,7 +195,6 @@ public abstract class MockRestRequestMatchers {
* subset of the body. The XPath expression can be a parameterized string
* using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the XPath optionally parameterized with arguments
* @param args arguments to parameterize the XPath expression with
*/
@@ -220,7 +207,6 @@ public abstract class MockRestRequestMatchers {
* subset of the body. The XPath expression can be a parameterized string
* using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the XPath optionally parameterized with arguments
* @param namespaces namespaces referenced in the XPath expression
* @param args arguments to parameterize the XPath expression with

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,8 +30,8 @@ import org.springframework.test.util.XmlExpectationsHelper;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for response content assertions. An instance of this class is
@@ -56,6 +56,7 @@ public class ContentResultMatchers {
this.jsonHelper = new JsonExpectationsHelper();
}
/**
* Assert the ServletResponse content type. The given content type must
* fully match including type, sub-type, and parameters. For checking
@@ -165,10 +166,8 @@ public class ContentResultMatchers {
* Parse the response content and the given string as XML and assert the two
* are "similar" - i.e. they contain the same elements and attributes
* regardless of order.
*
* <p>Use of this matcher requires the <a
* href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library.
*
* @param xmlContent the expected XML content
* @see MockMvcResultMatchers#xpath(String, Object...)
* @see MockMvcResultMatchers#xpath(String, Map, Object...)
@@ -200,7 +199,6 @@ public class ContentResultMatchers {
/**
* Parse the response content as {@link DOMSource} and apply the given
* Hamcrest {@link Matcher}.
*
* @see <a href="http://code.google.com/p/xml-matchers/">xml-matchers</a>
*/
public ResultMatcher source(final Matcher<? super Source> matcher) {
@@ -217,16 +215,13 @@ public class ContentResultMatchers {
* Parse the response content and the given string as JSON and assert the two
* are "similar" - i.e. they contain the same attribute-value pairs
* regardless of order and formatting.
*
* <p>Use of this matcher requires the <a
* href="http://jsonassert.skyscreamer.org/">JSONassert<a/> library.
*
* @param jsonContent the expected JSON content
* @since 4.1
*/
public ResultMatcher json(final String jsonContent) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
String content = result.getResponse().getContentAsString();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ import org.hamcrest.Matcher;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for response cookie assertions. An instance of this class is
@@ -36,7 +36,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class CookieResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#cookie()}.
@@ -44,6 +43,7 @@ public class CookieResultMatchers {
protected CookieResultMatchers() {
}
/**
* Assert a cookie value with the given Hamcrest {@link Matcher}.
*/
@@ -241,4 +241,5 @@ public class CookieResultMatchers {
}
};
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@ import org.hamcrest.Matcher;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for "output" flash attribute assertions. An instance of this class is
@@ -33,7 +33,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class FlashAttributeResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#flash()}.
@@ -41,6 +40,7 @@ public class FlashAttributeResultMatchers {
protected FlashAttributeResultMatchers() {
}
/**
* Assert a flash attribute's value with the given Hamcrest {@link Matcher}.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for assertions on the selected handler. An instance of this class is
@@ -39,7 +39,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class HandlerResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#handler()}.
@@ -47,6 +46,7 @@ public class HandlerResultMatchers {
protected HandlerResultMatchers() {
}
/**
* Assert the type of the handler that processed the request.
*/
@@ -68,7 +68,6 @@ public class HandlerResultMatchers {
/**
* Assert the name of the controller method that processed the request with
* the given Hamcrest {@link Matcher}.
*
* <p>Use of this method implies annotated controllers are processed with
* {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
*/
@@ -84,7 +83,6 @@ public class HandlerResultMatchers {
/**
* Assert the name of the controller method that processed the request.
*
* <p>Use of this method implies annotated controllers are processed with
* {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
*/
@@ -100,7 +98,6 @@ public class HandlerResultMatchers {
/**
* Assert the controller method that processed the request.
*
* <p>Use of this method implies annotated controllers are processed with
* {@link RequestMappingHandlerMapping} and {@link RequestMappingHandlerAdapter}.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,8 +21,8 @@ import org.hamcrest.Matcher;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for response header assertions. An instance of this
@@ -34,7 +34,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class HeaderResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#header()}.
@@ -48,7 +47,6 @@ public class HeaderResultMatchers {
*/
public ResultMatcher string(final String name, final Matcher<? super String> matcher) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertThat("Response header " + name, result.getResponse().getHeader(name), matcher);
@@ -61,7 +59,6 @@ public class HeaderResultMatchers {
*/
public ResultMatcher string(final String name, final String value) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertEquals("Response header " + name, value, result.getResponse().getHeader(name));
@@ -75,7 +72,6 @@ public class HeaderResultMatchers {
*/
public ResultMatcher doesNotExist(final String name) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertTrue("Response should not contain header " + name, !result.getResponse().containsHeader(name));
@@ -85,14 +81,12 @@ public class HeaderResultMatchers {
/**
* Assert the primary value of the named response header as a {@code long}.
*
* <p>The {@link ResultMatcher} returned by this method throws an {@link AssertionError}
* if the response does not contain the specified header, or if the supplied
* {@code value} does not match the primary value.
*/
public ResultMatcher longValue(final String name, final long value) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertTrue("Response does not contain header " + name, result.getResponse().containsHeader(name));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
/**
* Factory for assertions on the response content using <a
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expressions.
* Factory for assertions on the response content using
* <a href="http://goessner.net/articles/JsonPath/">JSONPath</a> expressions.
* An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#jsonPath}.
*
@@ -33,7 +33,8 @@ import org.springframework.test.web.servlet.ResultMatcher;
*/
public class JsonPathResultMatchers {
private JsonPathExpectationsHelper jsonPathHelper;
private final JsonPathExpectationsHelper jsonPathHelper;
/**
* Protected constructor. Use
@@ -44,6 +45,7 @@ public class JsonPathResultMatchers {
this.jsonPathHelper = new JsonPathExpectationsHelper(expression, args);
}
/**
* Evaluate the JSONPath and assert the value of the content found with the
* given Hamcrest {@code Matcher}.
@@ -108,4 +110,5 @@ public class JsonPathResultMatchers {
}
};
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,10 +31,6 @@ import org.springframework.util.CollectionUtils;
*/
public abstract class MockMvcResultHandlers {
private MockMvcResultHandlers() {
}
/**
* Print {@link MvcResult} details to the "standard" output stream.
*/
@@ -43,18 +39,18 @@ public abstract class MockMvcResultHandlers {
}
/** An {@link PrintingResultHandler} that writes to the "standard" output stream */
/**
* An {@link PrintingResultHandler} that writes to the "standard" output stream
*/
private static class ConsolePrintingResultHandler extends PrintingResultHandler {
public ConsolePrintingResultHandler() {
super(new ResultValuePrinter() {
@Override
public void printHeading(String heading) {
System.out.println();
System.out.println(String.format("%20s:", heading));
}
@Override
public void printValue(String label, Object value) {
if (value != null && value.getClass().isArray()) {
@@ -65,4 +61,5 @@ public abstract class MockMvcResultHandlers {
});
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,9 +42,6 @@ public abstract class MockMvcResultMatchers {
private static final AntPathMatcher pathMatcher = new AntPathMatcher();
private MockMvcResultMatchers() {
}
/**
* Access to request-related assertions.
*/
@@ -87,7 +84,6 @@ 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());
@@ -99,12 +95,11 @@ public abstract class MockMvcResultMatchers {
* Asserts the request was forwarded to the given URL.
* This methods accepts {@link org.springframework.util.AntPathMatcher} expressions.
* @param urlPattern an AntPath expression to match against
* @see org.springframework.util.AntPathMatcher
* @since 4.0
* @see org.springframework.util.AntPathMatcher
*/
public static ResultMatcher forwardedUrlPattern(final String urlPattern) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertTrue("AntPath expression", pathMatcher.isPattern(urlPattern));
@@ -121,7 +116,6 @@ 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());
@@ -138,7 +132,6 @@ public abstract class MockMvcResultMatchers {
*/
public static ResultMatcher redirectedUrlPattern(final String expectedUrl) {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
assertTrue("AntPath expression",pathMatcher.isPattern(expectedUrl));
@@ -175,7 +168,6 @@ public abstract class MockMvcResultMatchers {
* inspect a specific subset of the body. The JSON path expression can be a
* parameterized string using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the JSON path optionally parameterized with arguments
* @param args arguments to parameterize the JSON path expression with
*/
@@ -188,7 +180,6 @@ public abstract class MockMvcResultMatchers {
* href="http://goessner.net/articles/JsonPath/">JSONPath</a> expression to
* inspect a specific subset of the body and a Hamcrest match for asserting
* the value found at the JSON path.
*
* @param expression the JSON path expression
* @param matcher a matcher for the value expected at the JSON path
*/
@@ -201,7 +192,6 @@ public abstract class MockMvcResultMatchers {
* subset of the body. The XPath expression can be a parameterized string
* using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the XPath optionally parameterized with arguments
* @param args arguments to parameterize the XPath expression with
*/
@@ -214,7 +204,6 @@ public abstract class MockMvcResultMatchers {
* subset of the body. The XPath expression can be a parameterized string
* using formatting specifiers as defined in
* {@link String#format(String, Object...)}.
*
* @param expression the XPath optionally parameterized with arguments
* @param namespaces namespaces referenced in the XPath expression
* @param args arguments to parameterize the XPath expression with

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for assertions on the model. An instance of this class is
@@ -44,6 +44,7 @@ public class ModelResultMatchers {
protected ModelResultMatchers() {
}
/**
* Assert a model attribute value with the given Hamcrest {@link Matcher}.
*/

View File

@@ -18,7 +18,6 @@ package org.springframework.test.web.servlet.result;
import java.util.Enumeration;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpHeaders;
@@ -69,7 +68,6 @@ public class PrintingResultHandler implements ResultHandler {
*/
@Override
public final void handle(MvcResult result) throws Exception {
this.printer.printHeading("MockHttpServletRequest");
printRequest(result.getRequest());
@@ -92,7 +90,9 @@ public class PrintingResultHandler implements ResultHandler {
printResponse(result.getResponse());
}
/** Print the request */
/**
* Print the request.
*/
protected void printRequest(MockHttpServletRequest request) throws Exception {
this.printer.printValue("HTTP Method", request.getMethod());
this.printer.printValue("Request URI", request.getRequestURI());
@@ -139,7 +139,9 @@ public class PrintingResultHandler implements ResultHandler {
this.printer.printValue("Async result", asyncResult);
}
/** Print the handler */
/**
* Print the handler.
*/
protected void printHandler(Object handler, HandlerInterceptor[] interceptors) throws Exception {
if (handler == null) {
this.printer.printValue("Type", null);
@@ -156,7 +158,9 @@ public class PrintingResultHandler implements ResultHandler {
}
}
/** Print exceptions resolved through a HandlerExceptionResolver */
/**
* Print exceptions resolved through a HandlerExceptionResolver.
*/
protected void printResolvedException(Exception resolvedException) throws Exception {
if (resolvedException == null) {
this.printer.printValue("Type", null);
@@ -166,7 +170,9 @@ public class PrintingResultHandler implements ResultHandler {
}
}
/** Print the ModelAndView */
/**
* Print the ModelAndView.
*/
protected void printModelAndView(ModelAndView mav) throws Exception {
this.printer.printValue("View name", (mav != null) ? mav.getViewName() : null);
this.printer.printValue("View", (mav != null) ? mav.getView() : null);
@@ -188,7 +194,9 @@ public class PrintingResultHandler implements ResultHandler {
}
}
/** Print "output" flash attributes */
/**
* Print "output" flash attributes.
*/
protected void printFlashMap(FlashMap flashMap) throws Exception {
if (flashMap == null) {
this.printer.printValue("Attributes", null);
@@ -201,7 +209,9 @@ public class PrintingResultHandler implements ResultHandler {
}
}
/** Print the response */
/**
* Print the response.
*/
protected void printResponse(MockHttpServletResponse response) throws Exception {
this.printer.printValue("Status", response.getStatus());
this.printer.printValue("Error message", response.getErrorMessage());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@ import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.context.request.async.WebAsyncTask;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for assertions on the request. An instance of this class is
@@ -39,7 +39,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class RequestResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#request()}.
@@ -47,6 +46,7 @@ public class RequestResultMatchers {
protected RequestResultMatchers() {
}
/**
* Assert a request attribute value with the given Hamcrest {@link Matcher}.
* Whether asynchronous processing started, usually as a result of a

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.servlet.result;
import org.hamcrest.Matcher;
@@ -21,8 +22,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for assertions on the response status. An instance of this class is
@@ -35,7 +36,6 @@ import static org.springframework.test.util.MatcherAssertionErrors.*;
*/
public class StatusResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#status()}.
@@ -43,6 +43,7 @@ public class StatusResultMatchers {
protected StatusResultMatchers() {
}
/**
* Assert the response status code with the given Hamcrest {@link Matcher}.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,17 +22,18 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
import org.springframework.web.servlet.ModelAndView;
import static org.hamcrest.MatcherAssert.*;
import static org.springframework.test.util.AssertionErrors.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
* Factory for assertions on the selected view. An instance of this class is
* typically accessed via {@link MockMvcResultMatchers#view()}.
*
* @author Rossen Stoyanchev
* @since 3.2
*/
public class ViewResultMatchers {
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#view()}.
@@ -40,6 +41,7 @@ public class ViewResultMatchers {
protected ViewResultMatchers() {
}
/**
* Assert the selected view name with the given Hamcrest {@link Matcher}.
*/
@@ -67,4 +69,5 @@ public class ViewResultMatchers {
}
};
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,13 +43,10 @@ public class XpathResultMatchers {
* Protected constructor, not for direct instantiation. Use
* {@link MockMvcResultMatchers#xpath(String, Object...)} or
* {@link MockMvcResultMatchers#xpath(String, Map, Object...)}.
*
* @param expression the XPath expression
* @param namespaces XML namespaces referenced in the XPath expression, or {@code null}
* @param args arguments to parameterize the XPath expression with using the
* formatting specifiers defined in {@link String#format(String, Object...)}
*
* @throws XPathExpressionException
*/
protected XpathResultMatchers(String expression, Map<String, String> namespaces, Object ... args)
throws XPathExpressionException {