From 4116e6dd184a6944ab4ee29bef504597ebe4482c Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 17 Aug 2020 07:53:39 +0100 Subject: [PATCH] Pull up method to ConfiugrableMockMvcBuilder See gh-19647 --- .../servlet/setup/AbstractMockMvcBuilder.java | 1 + .../setup/ConfigurableMockMvcBuilder.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java index ab9b89c0aa..de05563d70 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java @@ -107,6 +107,7 @@ public abstract class AbstractMockMvcBuilder return self(); } + @Override public final T addDispatcherServletCustomizer(DispatcherServletCustomizer customizer) { this.dispatcherServletCustomizers.add(customizer); return self(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java index 31dbd4169b..a619ee7a58 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -18,6 +18,7 @@ package org.springframework.test.web.servlet.setup; import javax.servlet.Filter; +import org.springframework.test.web.servlet.DispatcherServletCustomizer; import org.springframework.test.web.servlet.MockMvcBuilder; import org.springframework.test.web.servlet.RequestBuilder; import org.springframework.test.web.servlet.ResultHandler; @@ -37,7 +38,7 @@ public interface ConfigurableMockMvcBuilder * mockMvcBuilder.addFilters(springSecurityFilterChain); * - *

is the equivalent of the following web.xml configuration: + *

It is the equivalent of the following web.xml configuration: *

 	 * <filter-mapping>
 	 *     <filter-name>springSecurityFilterChain</filter-name>
@@ -52,9 +53,9 @@ public interface ConfigurableMockMvcBuilder
-	 * mockMvcBuilder.addFilters(myResourceFilter, "/resources/*");
+	 * mockMvcBuilder.addFilter(myResourceFilter, "/resources/*");
 	 * 
- *

is the equivalent of: + *

It is the equivalent of: *

 	 * <filter-mapping>
 	 *     <filter-name>myResourceFilter</filter-name>
@@ -105,6 +106,13 @@ public interface ConfigurableMockMvcBuilder T dispatchOptions(boolean dispatchOptions);
 
+	/**
+	 * A more advanced variant of {@link #dispatchOptions(boolean)} that allows
+	 * customizing any {@link org.springframework.web.servlet.DispatcherServlet}
+	 * property.
+	 */
+	 T addDispatcherServletCustomizer(DispatcherServletCustomizer customizer);
+
 	/**
 	 * Add a {@code MockMvcConfigurer} that automates MockMvc setup and
 	 * configures it for some specific purpose (e.g. security).