19
19
import java .util .ArrayList ;
20
20
import java .util .List ;
21
21
22
+ import javax .servlet .Filter ;
22
23
import javax .servlet .ServletContext ;
23
24
24
25
import org .springframework .beans .Mergeable ;
@@ -54,7 +55,9 @@ public final class MockMvc {
54
55
55
56
static String MVC_RESULT_ATTRIBUTE = MockMvc .class .getName ().concat (".MVC_RESULT_ATTRIBUTE" );
56
57
57
- private final MockFilterChain filterChain ;
58
+ private final TestDispatcherServlet servlet ;
59
+
60
+ private final Filter [] filters ;
58
61
59
62
private final ServletContext servletContext ;
60
63
@@ -69,11 +72,15 @@ public final class MockMvc {
69
72
* Private constructor, not for direct instantiation.
70
73
* @see org.springframework.test.web.servlet.setup.MockMvcBuilders
71
74
*/
72
- MockMvc (MockFilterChain filterChain , ServletContext servletContext ) {
75
+ MockMvc (TestDispatcherServlet servlet , Filter [] filters , ServletContext servletContext ) {
76
+
77
+ Assert .notNull (servlet , "DispatcherServlet is required" );
78
+ Assert .notNull (filters , "filters cannot be null" );
79
+ Assert .noNullElements (filters , "filters cannot contain null values" );
73
80
Assert .notNull (servletContext , "A ServletContext is required" );
74
- Assert .notNull (filterChain , "A MockFilterChain is required" );
75
81
76
- this .filterChain = filterChain ;
82
+ this .servlet = servlet ;
83
+ this .filters = filters ;
77
84
this .servletContext = servletContext ;
78
85
}
79
86
@@ -130,8 +137,8 @@ public ResultActions perform(RequestBuilder requestBuilder) throws Exception {
130
137
final MvcResult mvcResult = new DefaultMvcResult (request , response );
131
138
request .setAttribute (MVC_RESULT_ATTRIBUTE , mvcResult );
132
139
133
- this .filterChain . reset ( );
134
- this . filterChain .doFilter (request , response );
140
+ MockFilterChain filterChain = new MockFilterChain ( this .servlet , this . filters );
141
+ filterChain .doFilter (request , response );
135
142
136
143
applyDefaultResultActions (mvcResult );
137
144
0 commit comments