Skip to content

Commit 1c3528f

Browse files
committed
Include Jackson Modules in WebMvcTest and WebFluxTest
Fixes gh-22530
1 parent 7b3c0a9 commit 1c3528f

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
2323

24+
import com.fasterxml.jackson.databind.Module;
25+
2426
import org.springframework.boot.context.TypeExcludeFilter;
2527
import org.springframework.boot.jackson.JsonComponent;
2628
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
@@ -54,6 +56,11 @@ public final class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizab
5456
includes.add(GenericConverter.class);
5557
includes.add(WebExceptionHandler.class);
5658
includes.add(WebFilter.class);
59+
try {
60+
includes.add(Module.class);
61+
}
62+
catch (Throwable ex) {
63+
}
5764
DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
5865
}
5966

spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
2323

24+
import com.fasterxml.jackson.databind.Module;
25+
2426
import org.springframework.boot.context.TypeExcludeFilter;
2527
import org.springframework.boot.jackson.JsonComponent;
2628
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
@@ -68,6 +70,11 @@ public final class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizabl
6870
includes.add(Converter.class);
6971
includes.add(GenericConverter.class);
7072
includes.add(HandlerInterceptor.class);
73+
try {
74+
includes.add(Module.class);
75+
}
76+
catch (Throwable ex) {
77+
}
7178
for (String optionalInclude : OPTIONAL_INCLUDES) {
7279
try {
7380
includes.add(ClassUtils.forName(optionalInclude, null));

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020

21+
import com.fasterxml.jackson.databind.module.SimpleModule;
2122
import org.junit.jupiter.api.Test;
2223
import reactor.core.publisher.Mono;
2324

@@ -57,6 +58,7 @@ void matchWhenHasNoControllers() throws Exception {
5758
assertThat(excludes(filter, ExampleService.class)).isTrue();
5859
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
5960
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
61+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
6062
}
6163

6264
@Test
@@ -69,6 +71,7 @@ void matchWhenHasController() throws Exception {
6971
assertThat(excludes(filter, ExampleService.class)).isTrue();
7072
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
7173
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
74+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
7275
}
7376

7477
@Test
@@ -81,6 +84,7 @@ void matchNotUsingDefaultFilters() throws Exception {
8184
assertThat(excludes(filter, ExampleService.class)).isTrue();
8285
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
8386
assertThat(excludes(filter, ExampleWebFilter.class)).isTrue();
87+
assertThat(excludes(filter, ExampleModule.class)).isTrue();
8488
}
8589

8690
@Test
@@ -93,6 +97,7 @@ void matchWithIncludeFilter() throws Exception {
9397
assertThat(excludes(filter, ExampleService.class)).isTrue();
9498
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
9599
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
100+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
96101
}
97102

98103
@Test
@@ -105,6 +110,7 @@ void matchWithExcludeFilter() throws Exception {
105110
assertThat(excludes(filter, ExampleService.class)).isTrue();
106111
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
107112
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
113+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
108114
}
109115

110116
private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
@@ -175,4 +181,8 @@ public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain web
175181

176182
}
177183

184+
static class ExampleModule extends SimpleModule {
185+
186+
}
187+
178188
}

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020

21+
import com.fasterxml.jackson.databind.module.SimpleModule;
2122
import org.junit.jupiter.api.Test;
2223

2324
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -57,6 +58,7 @@ void matchWhenHasNoControllers() throws Exception {
5758
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
5859
assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse();
5960
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
61+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
6062
}
6163

6264
@Test
@@ -71,6 +73,7 @@ void matchWhenHasController() throws Exception {
7173
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
7274
assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse();
7375
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
76+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
7477
}
7578

7679
@Test
@@ -85,6 +88,7 @@ void matchNotUsingDefaultFilters() throws Exception {
8588
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
8689
assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isTrue();
8790
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isTrue();
91+
assertThat(excludes(filter, ExampleModule.class)).isTrue();
8892
}
8993

9094
@Test
@@ -98,6 +102,7 @@ void matchWithIncludeFilter() throws Exception {
98102
assertThat(excludes(filter, ExampleService.class)).isTrue();
99103
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
100104
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
105+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
101106
}
102107

103108
@Test
@@ -112,6 +117,7 @@ void matchWithExcludeFilter() throws Exception {
112117
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
113118
assertThat(excludes(filter, ExampleWebSecurityConfigurer.class)).isFalse();
114119
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
120+
assertThat(excludes(filter, ExampleModule.class)).isFalse();
115121
}
116122

117123
private boolean excludes(WebMvcTypeExcludeFilter filter, Class<?> type) throws IOException {
@@ -185,4 +191,8 @@ static class ExampleHandlerInterceptor implements HandlerInterceptor {
185191

186192
}
187193

194+
static class ExampleModule extends SimpleModule {
195+
196+
}
197+
188198
}

0 commit comments

Comments
 (0)