Skip to content

Commit 9d052bb

Browse files
nosanmbhave
authored andcommitted
Include WebFilter beans in WebFluxTest slice
See gh-17601
1 parent 9f69b61 commit 9d052bb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTypeExcludeFilter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.web.bind.annotation.ControllerAdvice;
3232
import org.springframework.web.reactive.config.WebFluxConfigurer;
3333
import org.springframework.web.server.WebExceptionHandler;
34+
import org.springframework.web.server.WebFilter;
3435

3536
/**
3637
* {@link TypeExcludeFilter} for {@link WebFluxTest @WebFluxTest}.
@@ -51,6 +52,7 @@ class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizableTypeExclude
5152
includes.add(Converter.class);
5253
includes.add(GenericConverter.class);
5354
includes.add(WebExceptionHandler.class);
55+
includes.add(WebFilter.class);
5456
DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
5557
}
5658

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/reactive/WebFluxTypeExcludeFilterTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020

2121
import org.junit.jupiter.api.Test;
22+
import reactor.core.publisher.Mono;
2223

2324
import org.springframework.context.annotation.ComponentScan.Filter;
2425
import org.springframework.context.annotation.FilterType;
@@ -30,6 +31,9 @@
3031
import org.springframework.stereotype.Service;
3132
import org.springframework.web.bind.annotation.ControllerAdvice;
3233
import org.springframework.web.reactive.config.WebFluxConfigurer;
34+
import org.springframework.web.server.ServerWebExchange;
35+
import org.springframework.web.server.WebFilter;
36+
import org.springframework.web.server.WebFilterChain;
3337

3438
import static org.assertj.core.api.Assertions.assertThat;
3539

@@ -52,6 +56,7 @@ void matchWhenHasNoControllers() throws Exception {
5256
assertThat(excludes(filter, ExampleWeb.class)).isFalse();
5357
assertThat(excludes(filter, ExampleService.class)).isTrue();
5458
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
59+
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
5560
}
5661

5762
@Test
@@ -63,6 +68,7 @@ void matchWhenHasController() throws Exception {
6368
assertThat(excludes(filter, ExampleWeb.class)).isFalse();
6469
assertThat(excludes(filter, ExampleService.class)).isTrue();
6570
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
71+
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
6672
}
6773

6874
@Test
@@ -74,6 +80,7 @@ void matchNotUsingDefaultFilters() throws Exception {
7480
assertThat(excludes(filter, ExampleWeb.class)).isTrue();
7581
assertThat(excludes(filter, ExampleService.class)).isTrue();
7682
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
83+
assertThat(excludes(filter, ExampleWebFilter.class)).isTrue();
7784
}
7885

7986
@Test
@@ -85,6 +92,7 @@ void matchWithIncludeFilter() throws Exception {
8592
assertThat(excludes(filter, ExampleWeb.class)).isFalse();
8693
assertThat(excludes(filter, ExampleService.class)).isTrue();
8794
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
95+
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
8896
}
8997

9098
@Test
@@ -96,6 +104,7 @@ void matchWithExcludeFilter() throws Exception {
96104
assertThat(excludes(filter, ExampleWeb.class)).isFalse();
97105
assertThat(excludes(filter, ExampleService.class)).isTrue();
98106
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
107+
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
99108
}
100109

101110
private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
@@ -157,4 +166,13 @@ static class ExampleRepository {
157166

158167
}
159168

169+
static class ExampleWebFilter implements WebFilter {
170+
171+
@Override
172+
public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
173+
return null;
174+
}
175+
176+
}
177+
160178
}

0 commit comments

Comments
 (0)