Merge pull request #17600 from nosan
* pr/17600: Include HandlerInterceptor beans in WebMvcTest slice Closes gh-17600
This commit is contained in:
		
						commit
						9f69b61d49
					
				| 
						 | 
				
			
			@ -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));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue