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
This commit is contained in:
Brian Clozel 2020-10-22 20:02:45 +02:00
parent a601901a6c
commit 5eb1e26e10
2 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -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));
}
}