diff --git a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java index 4c1771de2cb..37cf2cfd3c1 100644 --- a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java @@ -44,17 +44,17 @@ import org.springframework.util.Assert; import org.springframework.util.function.ThrowingBiFunction; /** - * Base AssertJ {@link org.assertj.core.api.Assert assertions} that can be + * Base AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be * applied to a JSON document. * - *

Support evaluating {@linkplain JsonPath JSON path} expressions and + *

Supports evaluating {@linkplain JsonPath JSON path} expressions and * extracting a part of the document for further {@linkplain JsonPathValueAssert * assertions} on the value. * - *

Also support comparing the JSON document against a target, using + *

Also supports comparing the JSON document against a target, using * {@linkplain JSONCompare JSON Assert}. Resources that are loaded from * the classpath can be relative if a {@linkplain #withResourceLoadClass(Class) - * class} is provided. By default, {@code UTF-8} is used to load resources + * class} is provided. By default, {@code UTF-8} is used to load resources, * but this can be overridden using {@link #withCharset(Charset)}. * * @author Stephane Nicoll @@ -85,7 +85,7 @@ public abstract class AbstractJsonContentAssertPath can be converted to a value object using the given - * {@linkplain GenericHttpMessageConverter json message converter}. + * {@linkplain GenericHttpMessageConverter JSON message converter}. * @param json the JSON document to assert * @param jsonMessageConverter the converter to use * @param selfType the implementation type of this assert @@ -379,12 +379,13 @@ public abstract class AbstractJsonContentAssertResources can be loaded from an absolute location or relative to the + * specified class. For instance, specifying {@code com.example.MyClass} as + * the resource class allows you to use "my-file.json" to load + * {@code /com/example/my-file.json}. + * @param resourceLoadClass the class used to load resources, or {@code null} + * to only use absolute paths */ public SELF withResourceLoadClass(@Nullable Class resourceLoadClass) { this.resourceLoadClass = resourceLoadClass; @@ -393,8 +394,8 @@ public abstract class AbstractJsonContentAssertBy default, resources are loaded using {@code UTF-8}. * @param charset the charset to use, or {@code null} to use the default */ public SELF withCharset(@Nullable Charset charset) { diff --git a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java index 8a11e46e771..d066a12cd26 100644 --- a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java @@ -41,7 +41,7 @@ import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; /** - * Base AssertJ {@link org.assertj.core.api.Assert assertions} that can be + * Base AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be * applied to a JSON value. * *

In JSON, values must be one of the following data types: diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java b/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java index db0212feeb1..de4a35f80f9 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java @@ -30,7 +30,7 @@ public class JsonContentAssert extends AbstractJsonContentAssertPath can be converted to a value object using the given - * {@linkplain GenericHttpMessageConverter json message converter}. + * {@linkplain GenericHttpMessageConverter JSON message converter}. * @param json the JSON document to assert * @param jsonMessageConverter the converter to use */ diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java b/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java index 131ab830f86..f598e93ea5e 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java @@ -22,7 +22,7 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.lang.Nullable; /** - * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied + * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied * to a JSON value produced by evaluating a {@linkplain JsonPath JSON path} * expression. * diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssert.java index 98650cb5979..396e0cb21e1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletRequestAssert.java @@ -34,7 +34,7 @@ import org.springframework.util.function.SingletonSupplier; import org.springframework.web.context.request.async.DeferredResult; /** - * Base AssertJ {@link org.assertj.core.api.Assert assertions} that can be + * Base AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be * applied to an {@link HttpServletRequest}. * * @author Stephane Nicoll diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletResponseAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletResponseAssert.java index fe079f7a9d8..9b7f42946e5 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletResponseAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractHttpServletResponseAssert.java @@ -36,7 +36,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.util.function.SingletonSupplier; /** - * Base AssertJ {@link org.assertj.core.api.Assert assertions} that can be + * Base AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be * applied to any object that provides an {@link HttpServletResponse}. This * provides direct access to response assertions while also providing access to * a different top-level object. @@ -91,7 +91,7 @@ public abstract class AbstractHttpServletResponseAssert + * Examples:


 	 * // Check for the presence of the Accept header:
 	 * assertThat(response).headers().containsHeader(HttpHeaders.ACCEPT);
 	 *
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletRequestAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletRequestAssert.java
index 085ef98d9d3..b8c98ad7d53 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletRequestAssert.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletRequestAssert.java
@@ -19,8 +19,8 @@ package org.springframework.test.web.servlet.assertj;
 import org.springframework.mock.web.MockHttpServletRequest;
 
 /**
- * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied to
- * {@link MockHttpServletRequest}.
+ * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied
+ * to {@link MockHttpServletRequest}.
  *
  * @author Stephane Nicoll
  * @since 6.2
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java
index c320bea1012..9800b2865db 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java
@@ -56,7 +56,7 @@ public abstract class AbstractMockHttpServletResponseAssertExamples: 

+	 * 

Examples:


 	 * // Check that the response body is equal to "Hello World":
 	 * assertThat(response).bodyText().isEqualTo("Hello World");
 	 * 
@@ -70,7 +70,7 @@ public abstract class AbstractMockHttpServletResponseAssertExamples:

+	 * 

Examples:


 	 * // Check that the response body is strictly equal to the content of
 	 * // "/com/acme/sample/person-created.json":
 	 * assertThat(response).bodyJson()
@@ -82,7 +82,7 @@ public abstract class AbstractMockHttpServletResponseAssert
* The returned assert object also supports JSON path expressions. - *

Examples:


+	 * 

Examples:


 	 * // Check that the JSON document does not have an "error" element
 	 * assertThat(response).bodyJson().doesNotHavePath("$.error");
 	 *
@@ -114,7 +114,7 @@ public abstract class AbstractMockHttpServletResponseAssertExample: 

+	 * 

Example:


 	 * // Check that the forwarded URL starts with "/orders/":
 	 * assertThat(response).forwardedUrl().matchPattern("/orders/*);
 	 * 
@@ -127,7 +127,7 @@ public abstract class AbstractMockHttpServletResponseAssertExample:

+	 * 

Example:


 	 * // Check that the redirected URL starts with "/orders/":
 	 * assertThat(response).redirectedUrl().matchPattern("/orders/*);
 	 * 
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/CookieMapAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/CookieMapAssert.java index 681e1e21c92..fd287fadc74 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/CookieMapAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/CookieMapAssert.java @@ -26,8 +26,8 @@ import org.assertj.core.api.AbstractMapAssert; import org.assertj.core.api.Assertions; /** - * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied to - * {@link Cookie cookies}. + * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied + * to {@link Cookie cookies}. * * @author Brian Clozel * @author Stephane Nicoll diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java index 8c718080692..7513a74b35f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java @@ -39,20 +39,26 @@ final class DefaultMvcTestResult implements MvcTestResult { @Nullable private final GenericHttpMessageConverter jsonMessageConverter; - DefaultMvcTestResult(@Nullable MvcResult mvcResult, @Nullable Exception unresolvedException, @Nullable GenericHttpMessageConverter jsonMessageConverter) { + + DefaultMvcTestResult(@Nullable MvcResult mvcResult, @Nullable Exception unresolvedException, + @Nullable GenericHttpMessageConverter jsonMessageConverter) { + this.mvcResult = mvcResult; this.unresolvedException = unresolvedException; this.jsonMessageConverter = jsonMessageConverter; } + + @Override public MvcResult getMvcResult() { if (this.mvcResult == null) { throw new IllegalStateException( - "Request has failed with unresolved exception " + this.unresolvedException); + "Request failed with unresolved exception " + this.unresolvedException); } return this.mvcResult; } + @Override @Nullable public Exception getUnresolvedException() { return this.unresolvedException; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java index 20777fb4fb3..e97be143bdc 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java @@ -30,8 +30,8 @@ import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBui import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.MethodInvocationInfo; /** - * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied to - * a handler or handler method. + * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied + * to a handler or handler method. * @author Stephane Nicoll * @since 6.2 @@ -48,9 +48,9 @@ public class HandlerResultAssert extends AbstractObjectAssertVerifies first that the handler is a {@linkplain #isMethodHandler() * method handler}. - *

Example:


+	 * 

Example:


 	 * // Check that a GET to "/greet" is invoked on a "handleGreet" method name
-	 * assertThat(mvc.perform(get("/greet")).handler().method().hasName("sayGreet");
+	 * assertThat(mvc.perform(get("/greet")).handler().method().hasName("handleGreet");
 	 * 
*/ public MethodAssert method() { @@ -71,7 +71,7 @@ public class HandlerResultAssert extends AbstractObjectAssertExample:

+	 * 

Example:


 	 * // If the method has a return type, you can return the result of the invocation
 	 * assertThat(mvc.perform(get("/greet")).handler().isInvokedOn(
 	 *         GreetController.class, controller -> controller.sayGreet());
@@ -96,7 +96,7 @@ public class HandlerResultAssert extends AbstractObjectAssertExample: 

+	 * 

Example:


 	 * // Check that a GET to "/greet" is managed by GreetController
 	 * assertThat(mvc.perform(get("/greet")).handler().hasType(GreetController.class);
 	 * 
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java index cca3087f602..c0d4546e083 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java @@ -38,11 +38,12 @@ import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; /** - * Test Spring MVC applications with {@link MockMvc} for server request handling - * using {@link org.assertj.core.api.Assertions AssertJ}. + * {@code MockMvcTester} provides support for testing Spring MVC applications + * with {@link MockMvc} for server request handling using + * {@linkplain org.assertj.core.api.Assertions AssertJ}. * *

A tester instance can be created from a {@link WebApplicationContext}: - *


+ * 

  * // Create an instance with default settings
  * MockMvcTester mvc = MockMvcTester.from(applicationContext);
  *
@@ -51,30 +52,31 @@ import org.springframework.web.context.WebApplicationContext;
  *         builder -> builder.addFilters(filter).build());
  * 
* - *

A tester can be created standalone by providing the controller(s) to - * include in a standalone setup:


+ * 

A tester can be created in standalone mode by providing the controller(s) + * to include:


  * // Create an instance for PersonController
  * MockMvcTester mvc = MockMvcTester.of(new PersonController());
  * 
* - *

Once a test instance is available, you can perform requests in - * a similar fashion as with {@link MockMvc}, and wrapping the result in - * {@code assertThat} provides access to assertions. For instance: - *


+ * 

Once a tester instance is available, you can perform requests in a similar + * fashion as with {@link MockMvc}, and wrapping the result in + * {@code assertThat()} provides access to assertions. For instance: + *


  * // perform a GET on /hi and assert the response body is equal to Hello
  * assertThat(mvc.perform(get("/hi")))
  *         .hasStatusOk().hasBodyTextEqualTo("Hello");
  * 
* - *

A main difference with {@link MockMvc} is that an unresolved exception - * is not thrown directly. Rather an {@link MvcTestResult} is available - * with an {@link MvcTestResult#getUnresolvedException() unresolved - * exception}. You can assert that a request has failed unexpectedly: - *


- * // perform a GET on /hi and assert the response body is equal to Hello
+ * 

One main difference between {@link MockMvc} and {@code MockMvcTester} is + * that an unresolved exception is not thrown directly when using + * {@code MockMvcTester}. Rather an {@link MvcTestResult} is available with an + * {@linkplain MvcTestResult#getUnresolvedException() unresolved exception} + * which allows you to assert that a request failed unexpectedly: + *


+ * // perform a GET on /boom and assert the message for the the unresolved exception
  * assertThat(mvc.perform(get("/boom")))
  *         .hasUnresolvedException())
- * 		   .withMessage("Test exception");
+ *         .withMessage("Test exception");
  * 
* *

{@link MockMvcTester} can be configured with a list of @@ -120,7 +122,7 @@ public final class MockMvcTester { * @param applicationContext the application context to detect the Spring * MVC infrastructure and application controllers from * @param customizations a function that creates a {@link MockMvc} - * instance based on a {@link DefaultMockMvcBuilder}. + * instance based on a {@link DefaultMockMvcBuilder} * @see MockMvcBuilders#webAppContextSetup(WebApplicationContext) */ public static MockMvcTester from(WebApplicationContext applicationContext, @@ -204,7 +206,7 @@ public final class MockMvcTester { * request, wrapping the invocation in {@code assertThat}. The following * asserts that a {@linkplain MockMvcRequestBuilders#get(URI) GET} request * against "/greet" has an HTTP status code 200 (OK) and a simple body: - *

assertThat(mvc.perform(get("/greet")))
+	 * 
assertThat(mvc.perform(get("/greet")))
 	 *       .hasStatusOk()
 	 *       .body().asString().isEqualTo("Hello");
 	 * 
@@ -215,7 +217,7 @@ public final class MockMvcTester { * {@code /boom} throws an {@code IllegalStateException}, the following * asserts that the invocation has indeed failed with the expected error * message: - *
assertThat(mvc.perform(post("/boom")))
+	 * 
assertThat(mvc.perform(post("/boom")))
 	 *       .unresolvedException().isInstanceOf(IllegalStateException.class)
 	 *       .hasMessage("Expected");
 	 * 
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java index 0117a0a5a1d..73bcebdaccc 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java @@ -33,8 +33,8 @@ import org.springframework.validation.Errors; import org.springframework.web.servlet.ModelAndView; /** - * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied to - * a {@linkplain ModelAndView#getModel() model}. + * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied + * to a {@linkplain ModelAndView#getModel() model}. * * @author Stephane Nicoll * @since 6.2 @@ -51,7 +51,7 @@ public class ModelAssert extends AbstractMapAssertExample:

+	 * 

Example:


 	 * // Check that the "person" attribute in the model has 2 errors:
 	 * assertThat(...).model().extractingBindingResult("person").hasErrorsCount(2);
 	 * 
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java index db8745bc174..2101b158c20 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java @@ -22,18 +22,18 @@ import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MvcResult; /** - * Provide to the result of an executed request using {@link MockMvcTester} that + * Provides the result of an executed request using {@link MockMvcTester} that * is meant to be used with {@link org.assertj.core.api.Assertions#assertThat(AssertProvider) * assertThat}. * *

Can be in one of two distinct states: *

    - *
  1. The request processed successfully, even if it fails with an exception - * that has been resolved. {@link #getMvcResult()} is available and - * {@link #getUnresolvedException()} is {@code null}.
  2. - *
  3. The request failed unexpectedly with {@link #getUnresolvedException()} - * providing more information about the error. Any attempt to access - * {@link #getMvcResult() the result } fails with an exception.
  4. + *
  5. The request processed successfully, even if it failed with an exception + * that has been resolved. The {@linkplain #getMvcResult() result} is available, + * and {@link #getUnresolvedException()} will return {@code null}.
  6. + *
  7. The request failed unexpectedly. {@link #getUnresolvedException()} + * provides more information about the error, and any attempt to access the + * {@linkplain #getMvcResult() result} will fail with an exception.
  8. *
* * @author Stephane Nicoll @@ -44,10 +44,10 @@ import org.springframework.test.web.servlet.MvcResult; public interface MvcTestResult extends AssertProvider { /** - * Return the {@link MvcResult result} of the processing. - *

If the request has failed unexpectedly, this throws an - * {@link IllegalStateException}. + * Return the {@linkplain MvcResult result} of the processing. * @return the {@link MvcResult} + * @throw {@link IllegalStateException} if the request failed unexpectedly + * @see #getUnresolvedException() */ MvcResult getMvcResult(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java index 7c7ff332ec8..7f2225ae370 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java @@ -40,7 +40,7 @@ import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.web.servlet.ModelAndView; /** - * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied + * AssertJ {@linkplain org.assertj.core.api.Assert assertions} that can be applied * to {@link MvcTestResult}. * * @author Stephane Nicoll @@ -60,7 +60,7 @@ public class MvcTestResultAssert extends AbstractMockHttpServletResponseAssertExample:


+	 * the handler as the object to test.
+	 * 

For a method invocation on a controller, this is a relative method handler. + *

Example:


 	 * // Check that a GET to "/greet" is invoked on a "handleGreet" method name
-	 * assertThat(mvc.perform(get("/greet")).handler().method().hasName("sayGreet");
+	 * assertThat(mvc.perform(get("/greet")).handler().method().hasName("handleGreet");
 	 * 
*/ public HandlerResultAssert handler() { @@ -127,7 +127,7 @@ public class MvcTestResultAssert extends AbstractMockHttpServletResponseAssert resultMatcher.match(mvcResult)); + return super.satisfies(mvcTestResult -> resultMatcher.match(mvcResult)); } /** - * Apply the given {@link ResultHandler} to the actual mvc result. + * Apply the given {@link ResultHandler} to the actual MVC result. * @param resultHandler the result matcher to invoke */ public MvcTestResultAssert apply(ResultHandler resultHandler) { MvcResult mvcResult = getMvcResult(); - return satisfies(tmc -> resultHandler.handle(mvcResult)); + return satisfies(mvcTestResult -> resultHandler.handle(mvcResult)); } /** - * Verify that a {@link ModelAndView} is available with a view equals to - * the given one. For more advanced assertions, consider using - * {@link #viewName()} + * Verify that a {@link ModelAndView} is available with a view name equal to + * the given one. + *

For more advanced assertions, consider using {@link #viewName()}. * @param viewName the expected view name */ public MvcTestResultAssert hasViewName(String viewName) { @@ -212,7 +212,7 @@ public class MvcTestResultAssert extends AbstractMockHttpServletResponseAssert action) { + private void assertRequestFailed(Consumer action) { DefaultMvcTestResult result = new DefaultMvcTestResult(null, new IllegalStateException("Expected"), null); - assertThatIllegalStateException().isThrownBy(() -> action.accept(result)) - .withMessageContaining("Request has failed with unresolved exception"); + assertThatIllegalStateException() + .isThrownBy(() -> action.accept(result)) + .withMessageContaining("Request failed with unresolved exception"); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterIntegrationTests.java index 1a6f69daa3f..90f68c1f553 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterIntegrationTests.java @@ -300,14 +300,14 @@ public class MockMvcTesterIntegrationTests { void doesNotHaveUnresolvedExceptionWithUnresolvedException() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(perform(get("/error/1"))).doesNotHaveUnresolvedException()) - .withMessage("Expecting request to have succeeded but it has failed"); + .withMessage("Expected request to succeed, but it failed"); } @Test void hasUnresolvedExceptionWithoutUnresolvedException() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(perform(get("/greet"))).hasUnresolvedException()) - .withMessage("Expecting request to have failed but it has succeeded"); + .withMessage("Expected request to fail, but it succeeded"); } @Test @@ -321,10 +321,10 @@ public class MockMvcTesterIntegrationTests { void unresolvedExceptionWithSuccessfulRequest() { assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertThat(perform(get("/greet"))).unresolvedException()) - .withMessage("Expecting request to have failed but it has succeeded"); + .withMessage("Expected request to fail, but it succeeded"); } - // Check that assertions fail immediately if request has failed with unresolved exception + // Check that assertions fail immediately if request failed with unresolved exception @Test void assertAndApplyWithUnresolvedException() { @@ -409,7 +409,7 @@ public class MockMvcTesterIntegrationTests { MvcTestResult result = perform(get("/error/1")); assertThatExceptionOfType(AssertionError.class) .isThrownBy(() -> assertions.accept(result)) - .withMessageContainingAll("Request has failed unexpectedly:", + .withMessageContainingAll("Request failed unexpectedly:", ServletException.class.getName(), IllegalStateException.class.getName(), "Expected"); }