From fad663a1fe65693dad29606521b7a39ff590b48f Mon Sep 17 00:00:00 2001 From: Valeriy Zhirnov Date: Thu, 25 Jan 2018 08:52:28 +0300 Subject: [PATCH] Allow to execute a number of expectations together --- .../test/web/servlet/ResultActions.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/ResultActions.java b/spring-test/src/main/java/org/springframework/test/web/servlet/ResultActions.java index 083611f611ae..bc7a401024b9 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/ResultActions.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/ResultActions.java @@ -52,6 +52,38 @@ public interface ResultActions { */ ResultActions andExpect(ResultMatcher matcher) throws Exception; + /** + * Perform a number of expectation. + * + *

Example

+ *
+	 * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*
+	 *
+	 * mockMvc.perform(get("/person/1"))
+	 *   .andExpect(
+	 *     status().isOk(),
+	 *     content().contentType(MediaType.APPLICATION_JSON),
+	 *     jsonPath("$.person.name").value("Jason")
+	 *   );
+	 *
+	 * mockMvc.perform(post("/form"))
+	 *   .andExpect(
+	 *     status().isOk(),
+	 *     redirectedUrl("/person/1"),
+	 *     model().size(1),
+	 *     model().attributeExists("person"),
+	 *     flash().attributeCount(1),
+	 *     flash().attribute("message", "success!")
+	 *   );
+	 * 
+ */ + default ResultActions andExpect(ResultMatcher... matchers) throws Exception { + for (ResultMatcher matcher : matchers) { + this.andExpect(matcher); + } + return this; + } + /** * Perform a general action. *