From 5eb1e26e10b3a67a87ec8ef1e3840b7c90ca0838 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 22 Oct 2020 20:02:45 +0200 Subject: [PATCH] Add HttpEncodingAutoConfiguration to WebMvcTest Prior to this commit, tests using the `@WebMvcTest` annotation would not include the `HttpEncodingAutoConfiguration`. This means that, even if configured, the encoding filter would not be configured in MVC tests, resulting in an inconsistency with `@SpringBootTest` tests. This commit ensures that the `HttpEncodingAutoConfiguration` is included when `@WebMvcTest` is used. Fixes gh-23749 --- .../src/main/resources/META-INF/spring.factories | 1 + .../WebMvcTestAutoConfigurationIntegrationTests.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories index c7212e65273..7802ca14059 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring.factories @@ -152,6 +152,7 @@ org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration,\ org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration,\ org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration,\ org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration,\ +org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\ org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration # DefaultTestExecutionListenersPostProcessors diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestAutoConfigurationIntegrationTests.java index 52eac84b328..ec325a450ab 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTestAutoConfigurationIntegrationTests.java @@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAuto import org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration; import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration; +import org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.test.util.ReflectionTestUtils; @@ -76,4 +77,9 @@ class WebMvcTestAutoConfigurationIntegrationTests { "taskExecutor")).isSameAs(this.applicationContext.getBean("applicationTaskExecutor")); } + @Test + void httpEncodingAutoConfigurationWasImported() { + assertThat(this.applicationContext).has(importedAutoConfiguration(HttpEncodingAutoConfiguration.class)); + } + }