From 6859a89cf3d8e1f929c9c3e72d996af0aa18e5c0 Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Mon, 22 Jul 2019 11:51:03 +0300 Subject: [PATCH] Include HandlerInterceptor beans in WebMvcTest slice See gh-17600 --- .../web/servlet/WebMvcTypeExcludeFilter.java | 2 ++ .../web/servlet/WebMvcTypeExcludeFilterTests.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java index 28260e5f8b..77785766f9 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java @@ -35,6 +35,7 @@ import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** @@ -65,6 +66,7 @@ class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeF includes.add(ErrorAttributes.class); includes.add(Converter.class); includes.add(GenericConverter.class); + includes.add(HandlerInterceptor.class); for (String optionalInclude : OPTIONAL_INCLUDES) { try { includes.add(ClassUtils.forName(optionalInclude, null)); diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java index 87553ac522..e9480855fc 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java @@ -31,6 +31,7 @@ import org.springframework.stereotype.Controller; import org.springframework.stereotype.Repository; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import static org.assertj.core.api.Assertions.assertThat; @@ -55,6 +56,7 @@ class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleService.class)).isTrue(); assertThat(excludes(filter, ExampleRepository.class)).isTrue(); assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse(); + assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse(); } @Test @@ -68,6 +70,7 @@ class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleService.class)).isTrue(); assertThat(excludes(filter, ExampleRepository.class)).isTrue(); assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse(); + assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse(); } @Test @@ -81,6 +84,7 @@ class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleService.class)).isTrue(); assertThat(excludes(filter, ExampleRepository.class)).isTrue(); assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isTrue(); + assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isTrue(); } @Test @@ -93,6 +97,7 @@ class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleMessageConverter.class)).isFalse(); assertThat(excludes(filter, ExampleService.class)).isTrue(); assertThat(excludes(filter, ExampleRepository.class)).isFalse(); + assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse(); } @Test @@ -106,6 +111,7 @@ class WebMvcTypeExcludeFilterTests { assertThat(excludes(filter, ExampleService.class)).isTrue(); assertThat(excludes(filter, ExampleRepository.class)).isTrue(); assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse(); + assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse(); } private boolean excludes(WebMvcTypeExcludeFilter filter, Class type) throws IOException { @@ -175,4 +181,8 @@ class WebMvcTypeExcludeFilterTests { } + static class ExampleHandlerInterceptor implements HandlerInterceptor { + + } + }