An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#content}.
*
@@ -217,7 +218,6 @@ public class ContentResultMatchers {
* are "similar" - i.e. they contain the same attribute-value pairs
* regardless of formatting with a lenient checking (extensible, and non-strict array
* ordering).
- *
* @param jsonContent the expected JSON content
* @since 4.1
*/
@@ -226,19 +226,15 @@ 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 formatting.
- *
+ * 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 formatting.
*
Can compare in two modes, depending on {@code strict} parameter value:
*
- *
{@code true}: strict checking. Not extensible, and strict array ordering.
- *
{@code false}: lenient checking. Extensible, and non-strict array ordering.
+ *
{@code true}: strict checking. Not extensible, and strict array ordering.
+ *
{@code false}: lenient checking. Extensible, and non-strict array ordering.
*
- *
*
Use of this matcher requires the JSONassert library.
- *
* @param jsonContent the expected JSON content
* @param strict enables strict checking
* @since 4.2
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java
index 78bf09d05a..5e5238fc3e 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -26,6 +26,7 @@ import static org.springframework.test.util.AssertionErrors.*;
/**
* Factory for "output" flash attribute assertions.
+ *
*
An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#flash}.
*
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java
index 211ca9a783..64c583342d 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HandlerResultMatchers.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -29,13 +29,12 @@ import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBui
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.springframework.test.util.AssertionErrors.assertEquals;
-import static org.springframework.test.util.AssertionErrors.assertTrue;
-import static org.springframework.test.util.AssertionErrors.fail;
+import static org.hamcrest.MatcherAssert.*;
+import static org.springframework.test.util.AssertionErrors.*;
/**
* Factory for assertions on the selected handler or handler method.
+ *
*
An instance of this class is typically accessed via
* {@link MockMvcResultMatchers#handler}.
*
@@ -50,7 +49,6 @@ import static org.springframework.test.util.AssertionErrors.fail;
*/
public class HandlerResultMatchers {
-
/**
* Protected constructor.
* Use {@link MockMvcResultMatchers#handler()}.
@@ -67,7 +65,7 @@ public class HandlerResultMatchers {
@Override
public void match(MvcResult result) throws Exception {
Object handler = result.getHandler();
- assertTrue("No handler: ", handler != null);
+ assertTrue("No handler", handler != null);
Class> actual = handler.getClass();
if (HandlerMethod.class.isInstance(handler)) {
actual = ((HandlerMethod) handler).getBeanType();
@@ -98,7 +96,6 @@ public class HandlerResultMatchers {
* mockMvc.perform(get("/"))
* .andExpect(handler().methodCall(on(SimpleController.class).handle()));
*
- *
* @param obj either the value returned from a "mock" controller invocation
* or the "mock" controller itself after an invocation
*/
@@ -106,9 +103,9 @@ public class HandlerResultMatchers {
return new ResultMatcher() {
@Override
public void match(MvcResult result) throws Exception {
- if (!MethodInvocationInfo.class.isInstance(obj)) {
- fail(String.format("The supplied object [%s] is not an instance of %s. "
- + "Ensure that you invoke the handler method via MvcUriComponentsBuilder.on().",
+ if (!(obj instanceof MethodInvocationInfo)) {
+ fail(String.format("The supplied object [%s] is not an instance of %s. " +
+ "Ensure that you invoke the handler method via MvcUriComponentsBuilder.on().",
obj, MethodInvocationInfo.class.getName()));
}
MethodInvocationInfo invocationInfo = (MethodInvocationInfo) obj;
@@ -159,6 +156,7 @@ public class HandlerResultMatchers {
};
}
+
private static HandlerMethod getHandlerMethod(MvcResult result) {
Object handler = result.getHandler();
assertTrue("No handler: ", handler != null);
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java
index aac0bab91a..052c19041d 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/HeaderResultMatchers.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -29,12 +29,12 @@ import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.ResultMatcher;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.springframework.test.util.AssertionErrors.assertEquals;
-import static org.springframework.test.util.AssertionErrors.assertTrue;
+import static org.hamcrest.MatcherAssert.*;
+import static org.springframework.test.util.AssertionErrors.*;
/**
* Factory for response header assertions.
+ *
*
An instance of this class is available via
* {@link MockMvcResultMatchers#header}.
*
@@ -45,7 +45,6 @@ import static org.springframework.test.util.AssertionErrors.assertTrue;
*/
public class HeaderResultMatchers {
-
/**
* Protected constructor.
* See {@link MockMvcResultMatchers#header()}.
@@ -62,7 +61,7 @@ public class HeaderResultMatchers {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
- assertThat("Response header " + name, result.getResponse().getHeader(name), matcher);
+ assertThat("Response header '" + name + "'", result.getResponse().getHeader(name), matcher);
}
};
}
@@ -77,7 +76,7 @@ public class HeaderResultMatchers {
@Override
public void match(MvcResult result) {
List values = result.getResponse().getHeaders(name);
- assertThat("Response header " + name, values, matcher);
+ assertThat("Response header '" + name + "'", values, matcher);
}
};
}
@@ -89,7 +88,7 @@ public class HeaderResultMatchers {
return new ResultMatcher() {
@Override
public void match(MvcResult result) {
- assertEquals("Response header " + name, value, result.getResponse().getHeader(name));
+ assertEquals("Response header '" + name + "'", value, result.getResponse().getHeader(name));
}
};
}
@@ -103,7 +102,7 @@ public class HeaderResultMatchers {
@Override
public void match(MvcResult result) {
List