Browse Source

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.
pull/759/head
Juergen Hoeller 10 years ago
parent
commit
4e1af7d195
  1. 4
      spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java
  2. 36
      spring-test/src/main/java/org/springframework/test/util/MatcherAssertionErrors.java
  3. 4
      spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java
  4. 19
      spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java
  5. 5
      spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java
  6. 22
      spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java
  7. 11
      spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java
  8. 7
      spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java
  9. 6
      spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java
  10. 9
      spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java
  11. 10
      spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java
  12. 11
      spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java
  13. 13
      spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java
  14. 15
      spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java
  15. 5
      spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java
  16. 26
      spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java
  17. 6
      spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java
  18. 7
      spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java
  19. 9
      spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java
  20. 5
      spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java
  21. 21
      spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java

4
spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.

36
spring-test/src/main/java/org/springframework/test/util/MatcherAssertionErrors.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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 { @@ -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 { @@ -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());
}
}

4
spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.

19
spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -222,4 +217,4 @@ public class XpathExpectationsHelper {
assertEquals("XPath " + this.expression, expectedValue, Boolean.parseBoolean(actual));
}
}
}

5
spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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

22
spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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.*; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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

11
spring-test/src/main/java/org/springframework/test/web/servlet/result/ContentResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();

7
spring-test/src/main/java/org/springframework/test/web/servlet/result/CookieResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.*; @@ -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 { @@ -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 { @@ -241,4 +241,5 @@ public class CookieResultMatchers {
}
};
}
}

6
spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.*; @@ -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 { @@ -41,6 +40,7 @@ public class FlashAttributeResultMatchers {
protected FlashAttributeResultMatchers() {
}
/**
* Assert a flash attribute's value with the given Hamcrest {@link Matcher}.
*/

9
spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.*; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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}.
*/

10
spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.*; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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));

11
spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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; @@ -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 { @@ -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 { @@ -108,4 +110,5 @@ public class JsonPathResultMatchers {
}
};
}
}

13
spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -65,4 +61,5 @@ public abstract class MockMvcResultHandlers {
});
}
}
}

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

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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

5
spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -44,6 +44,7 @@ public class ModelResultMatchers {
protected ModelResultMatchers() {
}
/**
* Assert a model attribute value with the given Hamcrest {@link Matcher}.
*/

26
spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java

@ -18,7 +18,6 @@ package org.springframework.test.web.servlet.result; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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());

6
spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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.*; @@ -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 { @@ -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

7
spring-test/src/main/java/org/springframework/test/web/servlet/result/StatusResultMatchers.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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; @@ -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.*; @@ -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 { @@ -43,6 +43,7 @@ public class StatusResultMatchers {
protected StatusResultMatchers() {
}
/**
* Assert the response status code with the given Hamcrest {@link Matcher}.
*/

9
spring-test/src/main/java/org/springframework/test/web/servlet/result/ViewResultMatchers.java

@ -1,5 +1,5 @@ @@ -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; @@ -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 { @@ -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 { @@ -67,4 +69,5 @@ public class ViewResultMatchers {
}
};
}
}

5
spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 {

21
spring-test/src/test/java/org/springframework/test/web/servlet/setup/ConditionalDelegatingFilterProxyTests.java

@ -12,7 +12,6 @@ @@ -12,7 +12,6 @@
*/
package org.springframework.test.web.servlet.setup;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@ -28,20 +27,25 @@ import org.springframework.mock.web.MockFilterConfig; @@ -28,20 +27,25 @@ import org.springframework.mock.web.MockFilterConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.springframework.test.util.MatcherAssertionErrors.*;
/**
*
* @author Rob Winch
*/
public class ConditionalDelegatingFilterProxyTests {
private MockHttpServletRequest request;
private MockHttpServletResponse response;
private MockFilterChain filterChain;
private MockFilter delegate;
private PatternMappingFilterProxy filter;
@Before
public void setup() {
request = new MockHttpServletRequest();
@ -51,6 +55,7 @@ public class ConditionalDelegatingFilterProxyTests { @@ -51,6 +55,7 @@ public class ConditionalDelegatingFilterProxyTests {
delegate = new MockFilter();
}
@Test
public void init() throws Exception {
FilterConfig config = new MockFilterConfig();
@ -245,11 +250,17 @@ public class ConditionalDelegatingFilterProxyTests { @@ -245,11 +250,17 @@ public class ConditionalDelegatingFilterProxyTests {
delegate = new MockFilter();
}
private static class MockFilter implements Filter {
private FilterConfig filterConfig;
private ServletRequest request;
private ServletResponse response;
private FilterChain chain;
private boolean destroy;
@Override
@ -258,8 +269,7 @@ public class ConditionalDelegatingFilterProxyTests { @@ -258,8 +269,7 @@ public class ConditionalDelegatingFilterProxyTests {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
this.request = request;
this.response = response;
this.chain = chain;
@ -270,4 +280,5 @@ public class ConditionalDelegatingFilterProxyTests { @@ -270,4 +280,5 @@ public class ConditionalDelegatingFilterProxyTests {
this.destroy = true;
}
}
}

Loading…
Cancel
Save