Skip to content

Commit e7cfe6b

Browse files
committed
Add tests for WebMvcResourceHandlerRegistryCustomizer
Signed-off-by: EinNxk <einnxk@gmail.com>
1 parent f6057e9 commit e7cfe6b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

module/spring-boot-webmvc/src/test/java/org/springframework/boot/webmvc/autoconfigure/WebMvcAutoConfigurationTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfiguration.WebMvcAutoConfigurationAdapter;
7171
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfigurationTests.OrderedControllerAdviceBeansConfiguration.HighestOrderedControllerAdvice;
7272
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfigurationTests.OrderedControllerAdviceBeansConfiguration.LowestOrderedControllerAdvice;
73+
import org.springframework.boot.webmvc.autoconfigure.WebMvcAutoConfigurationTests.WebMcvResourceHandlerCustomizersConfiguration.TestWebMcvResourceHandlerRegistryCustomizer;
7374
import org.springframework.context.ApplicationContext;
7475
import org.springframework.context.annotation.Bean;
7576
import org.springframework.context.annotation.Configuration;
@@ -1196,6 +1197,18 @@ void registersRuntimeHintsForValidatorCreation() {
11961197
assertThat(RuntimeHintsPredicates.reflection().onType(ValidatorAdapter.class)).accepts(hints);
11971198
}
11981199

1200+
@Test
1201+
void resourceHandlerRegistryCustomizerIsInvoked() {
1202+
this.contextRunner
1203+
.withUserConfiguration(WebMcvResourceHandlerCustomizersConfiguration.class)
1204+
.run((context) -> {
1205+
WebMvcResourceHandlerRegistryCustomizer customizer =
1206+
context.getBean(WebMvcResourceHandlerRegistryCustomizer.class);
1207+
1208+
assertThat(((TestWebMcvResourceHandlerRegistryCustomizer) customizer).invoked).isTrue();
1209+
});
1210+
}
1211+
11991212
private void assertResourceHttpRequestHandler(AssertableWebApplicationContext context,
12001213
Consumer<ResourceHttpRequestHandler> handlerConsumer) {
12011214
Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class));
@@ -1805,6 +1818,25 @@ ServerHttpMessageConvertersCustomizer customizer3() {
18051818

18061819
}
18071820

1821+
@Configuration(proxyBeanMethods = false)
1822+
static class WebMcvResourceHandlerCustomizersConfiguration {
1823+
1824+
@Bean
1825+
WebMvcResourceHandlerRegistryCustomizer customizer() {
1826+
return new WebMvcAutoConfigurationTests.WebMcvResourceHandlerCustomizersConfiguration.TestWebMcvResourceHandlerRegistryCustomizer();
1827+
}
1828+
1829+
static class TestWebMcvResourceHandlerRegistryCustomizer implements WebMvcResourceHandlerRegistryCustomizer {
1830+
1831+
public boolean invoked;
1832+
1833+
@Override
1834+
public void customize(ResourceHandlerRegistry registry) {
1835+
this.invoked = true;
1836+
}
1837+
}
1838+
}
1839+
18081840
static class FormattedDate {
18091841

18101842
@DateTimeFormat(pattern = "${my.date.format}")

0 commit comments

Comments
 (0)