11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -50,6 +50,8 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
5050
5151 private Boolean dispatchOptions = Boolean .FALSE ;
5252
53+ private final List <MockMvcConfigurer > configurers = new ArrayList <MockMvcConfigurer >(4 );
54+
5355
5456
5557 /**
@@ -166,16 +168,28 @@ public final <T extends B> T alwaysDo(ResultHandler resultHandler) {
166168 }
167169
168170 /**
169- * Should the {@link org.springframework.web.servlet. DispatcherServlet} dispatch OPTIONS request to controllers.
170- * @param dispatchOptions
171- * @see org.springframework.web.servlet.DispatcherServlet#setDispatchOptionsRequest(boolean)
171+ * Whether to enable the DispatcherServlet property
172+ * {@link org.springframework.web.servlet.DispatcherServlet#setDispatchOptionsRequest
173+ * dispatchOptionsRequest} which allows processing of HTTP OPTIONS requests.
172174 */
173175 @ SuppressWarnings ("unchecked" )
174176 public final <T extends B > T dispatchOptions (boolean dispatchOptions ) {
175177 this .dispatchOptions = dispatchOptions ;
176178 return (T ) this ;
177179 }
178180
181+ /**
182+ * Add a {@code MockMvcConfigurer} which encapsulates ways to further configure
183+ * this MockMvcBuilder with some specific purpose in mind.
184+ */
185+ @ SuppressWarnings ("unchecked" )
186+ public final <T extends B > T add (MockMvcConfigurer configurer ) {
187+ configurer .afterConfigurerAdded (this );
188+ this .configurers .add (configurer );
189+ return (T ) this ;
190+ }
191+
192+
179193 /**
180194 * Build a {@link org.springframework.test.web.servlet.MockMvc} instance.
181195 */
@@ -187,6 +201,10 @@ public final MockMvc build() {
187201 ServletContext servletContext = wac .getServletContext ();
188202 MockServletConfig mockServletConfig = new MockServletConfig (servletContext );
189203
204+ for (MockMvcConfigurer configurer : this .configurers ) {
205+ configurer .beforeMockMvcCreated (this , this .defaultRequestBuilder , wac );
206+ }
207+
190208 Filter [] filterArray = this .filters .toArray (new Filter [this .filters .size ()]);
191209
192210 return super .createMockMvc (filterArray , mockServletConfig , wac , this .defaultRequestBuilder ,
0 commit comments