Skip to content

Commit 7f8ea33

Browse files
committed
Merge branch '2.4.x'
Closes gh-25073
2 parents 0104ee6 + 79c0597 commit 7f8ea33

File tree

5 files changed

+48
-19
lines changed

5 files changed

+48
-19
lines changed

spring-boot-project/spring-boot-test-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ dependencies {
8484
testImplementation("org.testcontainers:mongodb")
8585
testImplementation("org.testcontainers:neo4j")
8686
testImplementation("org.testcontainers:testcontainers")
87+
testImplementation("org.thymeleaf:thymeleaf")
8788

8889
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
8990
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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,14 +21,13 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
2323

24-
import com.fasterxml.jackson.databind.Module;
25-
2624
import org.springframework.boot.context.TypeExcludeFilter;
2725
import org.springframework.boot.jackson.JsonComponent;
2826
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
2927
import org.springframework.core.convert.converter.Converter;
3028
import org.springframework.core.convert.converter.GenericConverter;
3129
import org.springframework.stereotype.Controller;
30+
import org.springframework.util.ClassUtils;
3231
import org.springframework.util.ObjectUtils;
3332
import org.springframework.web.bind.annotation.ControllerAdvice;
3433
import org.springframework.web.reactive.config.WebFluxConfigurer;
@@ -45,6 +44,9 @@ public final class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizab
4544

4645
private static final Class<?>[] NO_CONTROLLERS = {};
4746

47+
private static final String[] OPTIONAL_INCLUDES = { "com.fasterxml.jackson.databind.Module",
48+
"org.thymeleaf.dialect.IDialect" };
49+
4850
private static final Set<Class<?>> DEFAULT_INCLUDES;
4951

5052
static {
@@ -56,10 +58,13 @@ public final class WebFluxTypeExcludeFilter extends StandardAnnotationCustomizab
5658
includes.add(GenericConverter.class);
5759
includes.add(WebExceptionHandler.class);
5860
includes.add(WebFilter.class);
59-
try {
60-
includes.add(Module.class);
61-
}
62-
catch (Throwable ex) {
61+
for (String optionalInclude : OPTIONAL_INCLUDES) {
62+
try {
63+
includes.add(ClassUtils.forName(optionalInclude, null));
64+
}
65+
catch (Exception ex) {
66+
// Ignore
67+
}
6368
}
6469
DEFAULT_INCLUDES = Collections.unmodifiableSet(includes);
6570
}

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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,8 +21,6 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Set;
2323

24-
import com.fasterxml.jackson.databind.Module;
25-
2624
import org.springframework.boot.context.TypeExcludeFilter;
2725
import org.springframework.boot.jackson.JsonComponent;
2826
import org.springframework.boot.test.autoconfigure.filter.StandardAnnotationCustomizableTypeExcludeFilter;
@@ -51,9 +49,9 @@ public final class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizabl
5149

5250
private static final Class<?>[] NO_CONTROLLERS = {};
5351

54-
private static final String[] OPTIONAL_INCLUDES = {
52+
private static final String[] OPTIONAL_INCLUDES = { "com.fasterxml.jackson.databind.Module",
5553
"org.springframework.security.config.annotation.web.WebSecurityConfigurer",
56-
"org.springframework.security.web.SecurityFilterChain" };
54+
"org.springframework.security.web.SecurityFilterChain", "org.thymeleaf.dialect.IDialect" };
5755

5856
private static final Set<Class<?>> DEFAULT_INCLUDES;
5957

@@ -71,11 +69,6 @@ public final class WebMvcTypeExcludeFilter extends StandardAnnotationCustomizabl
7169
includes.add(Converter.class);
7270
includes.add(GenericConverter.class);
7371
includes.add(HandlerInterceptor.class);
74-
try {
75-
includes.add(Module.class);
76-
}
77-
catch (Throwable ex) {
78-
}
7972
for (String optionalInclude : OPTIONAL_INCLUDES) {
8073
try {
8174
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: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -20,6 +20,7 @@
2020

2121
import com.fasterxml.jackson.databind.module.SimpleModule;
2222
import org.junit.jupiter.api.Test;
23+
import org.thymeleaf.dialect.IDialect;
2324
import reactor.core.publisher.Mono;
2425

2526
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -59,6 +60,7 @@ void matchWhenHasNoControllers() throws Exception {
5960
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
6061
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
6162
assertThat(excludes(filter, ExampleModule.class)).isFalse();
63+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
6264
}
6365

6466
@Test
@@ -72,6 +74,7 @@ void matchWhenHasController() throws Exception {
7274
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
7375
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
7476
assertThat(excludes(filter, ExampleModule.class)).isFalse();
77+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
7578
}
7679

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

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

103108
@Test
@@ -111,6 +116,7 @@ void matchWithExcludeFilter() throws Exception {
111116
assertThat(excludes(filter, ExampleRepository.class)).isTrue();
112117
assertThat(excludes(filter, ExampleWebFilter.class)).isFalse();
113118
assertThat(excludes(filter, ExampleModule.class)).isFalse();
119+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
114120
}
115121

116122
private boolean excludes(WebFluxTypeExcludeFilter filter, Class<?> type) throws IOException {
@@ -185,4 +191,13 @@ static class ExampleModule extends SimpleModule {
185191

186192
}
187193

194+
static class ExampleDialect implements IDialect {
195+
196+
@Override
197+
public String getName() {
198+
return "example";
199+
}
200+
201+
}
202+
188203
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -20,6 +20,7 @@
2020

2121
import com.fasterxml.jackson.databind.module.SimpleModule;
2222
import org.junit.jupiter.api.Test;
23+
import org.thymeleaf.dialect.IDialect;
2324

2425
import org.springframework.context.annotation.ComponentScan.Filter;
2526
import org.springframework.context.annotation.FilterType;
@@ -61,6 +62,7 @@ void matchWhenHasNoControllers() throws Exception {
6162
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
6263
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
6364
assertThat(excludes(filter, ExampleModule.class)).isFalse();
65+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
6466
}
6567

6668
@Test
@@ -77,6 +79,7 @@ void matchWhenHasController() throws Exception {
7779
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
7880
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
7981
assertThat(excludes(filter, ExampleModule.class)).isFalse();
82+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
8083
}
8184

8285
@Test
@@ -93,6 +96,7 @@ void matchNotUsingDefaultFilters() throws Exception {
9396
assertThat(excludes(filter, SecurityFilterChain.class)).isTrue();
9497
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isTrue();
9598
assertThat(excludes(filter, ExampleModule.class)).isTrue();
99+
assertThat(excludes(filter, ExampleDialect.class)).isTrue();
96100
}
97101

98102
@Test
@@ -107,6 +111,7 @@ void matchWithIncludeFilter() throws Exception {
107111
assertThat(excludes(filter, ExampleRepository.class)).isFalse();
108112
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
109113
assertThat(excludes(filter, ExampleModule.class)).isFalse();
114+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
110115
}
111116

112117
@Test
@@ -123,6 +128,7 @@ void matchWithExcludeFilter() throws Exception {
123128
assertThat(excludes(filter, SecurityFilterChain.class)).isFalse();
124129
assertThat(excludes(filter, ExampleHandlerInterceptor.class)).isFalse();
125130
assertThat(excludes(filter, ExampleModule.class)).isFalse();
131+
assertThat(excludes(filter, ExampleDialect.class)).isFalse();
126132
}
127133

128134
private boolean excludes(WebMvcTypeExcludeFilter filter, Class<?> type) throws IOException {
@@ -200,4 +206,13 @@ static class ExampleModule extends SimpleModule {
200206

201207
}
202208

209+
static class ExampleDialect implements IDialect {
210+
211+
@Override
212+
public String getName() {
213+
return "example";
214+
}
215+
216+
}
217+
203218
}

0 commit comments

Comments
 (0)