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 083611f611a..d1e11f3c1e0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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. @@ -40,14 +40,21 @@ public interface ResultActions { * .andExpect(status().isOk()) * .andExpect(content().contentType(MediaType.APPLICATION_JSON)) * .andExpect(jsonPath("$.person.name").value("Jason")); + * + * + *
Or alternatively provide all matchers as a vararg: + *
+ * static imports: MockMvcRequestBuilders.*, MockMvcResultMatchers.*, ResultMatcher.matchAll
*
* mockMvc.perform(post("/form"))
- * .andExpect(status().isOk())
- * .andExpect(redirectedUrl("/person/1"))
- * .andExpect(model().size(1))
- * .andExpect(model().attributeExists("person"))
- * .andExpect(flash().attributeCount(1))
- * .andExpect(flash().attribute("message", "success!"));
+ * .andExpect(matchAll(
+ * status().isOk(),
+ * redirectedUrl("/person/1"),
+ * model().size(1),
+ * model().attributeExists("person"),
+ * flash().attributeCount(1),
+ * flash().attribute("message", "success!"))
+ * );
*
*/
ResultActions andExpect(ResultMatcher matcher) throws Exception;
diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/ResultMatcher.java b/spring-test/src/main/java/org/springframework/test/web/servlet/ResultMatcher.java
index 332019fb822..4ecda82d0af 100644
--- a/spring-test/src/main/java/org/springframework/test/web/servlet/ResultMatcher.java
+++ b/spring-test/src/main/java/org/springframework/test/web/servlet/ResultMatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2018 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.
@@ -49,12 +49,26 @@ package org.springframework.test.web.servlet;
@FunctionalInterface
public interface ResultMatcher {
+
/**
* Assert the result of an executed request.
- *
* @param result the result of the executed request
* @throws Exception if a failure occurs
*/
void match(MvcResult result) throws Exception;
+
+ /**
+ * Static method for matching with an array of result matchers.
+ * @param matchers the matchers
+ * @since 5.1
+ */
+ static ResultMatcher matchAll(ResultMatcher... matchers) {
+ return result -> {
+ for (ResultMatcher matcher : matchers) {
+ matcher.match(result);
+ }
+ };
+ }
+
}