Browse Source

Merge pull request #17600 from nosan

* pr/17600:
  Include HandlerInterceptor beans in WebMvcTest slice

Closes gh-17600
pull/17611/head
Madhura Bhave 7 years ago
parent
commit
9f69b61d49
  1. 2
      spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java
  2. 10
      spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java

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

10
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; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -175,4 +181,8 @@ class WebMvcTypeExcludeFilterTests {
}
static class ExampleHandlerInterceptor implements HandlerInterceptor {
}
}

Loading…
Cancel
Save