Skip to content

Commit 6ad4863

Browse files
committed
Back port 246c4a2 to 3.3.x
The changes do not apply cleanly when cherry-picked so they have been redone manually. Closes gh-44941
1 parent bed6ad3 commit 6ad4863

File tree

6 files changed

+42
-13
lines changed

6 files changed

+42
-13
lines changed

buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java

+29
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static List<ArchRule> standard() {
8787
rules.add(noClassesShouldCallStringToUpperCaseWithoutLocale());
8888
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
8989
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
90+
rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType());
9091
return List.copyOf(rules);
9192
}
9293

@@ -201,6 +202,34 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
201202
});
202203
}
203204

205+
private static ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() {
206+
return ArchRuleDefinition.methods()
207+
.that()
208+
.areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource")
209+
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType())
210+
.allowEmptyShould(true);
211+
}
212+
213+
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType() {
214+
return check("not specify only a type that is the same as the method's parameter type",
215+
ArchitectureRules::notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType);
216+
}
217+
218+
private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(JavaMethod item,
219+
ConditionEvents events) {
220+
JavaAnnotation<JavaMethod> enumSourceAnnotation = item
221+
.getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource");
222+
Map<String, Object> properties = enumSourceAnnotation.getProperties();
223+
if (properties.size() == 1 && item.getParameterTypes().size() == 1) {
224+
enumSourceAnnotation.get("value").ifPresent((value) -> {
225+
if (value.equals(item.getParameterTypes().get(0))) {
226+
addViolation(events, item, enumSourceAnnotation.getDescription()
227+
+ " should not specify only a value that is the same as the method's parameter type");
228+
}
229+
});
230+
}
231+
}
232+
204233
private static boolean containsOnlySingleType(JavaType[] types, JavaType type) {
205234
return types.length == 1 && type.equals(types[0]);
206235
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -57,7 +57,7 @@ void setup() {
5757
}
5858

5959
@ParameterizedTest
60-
@EnumSource(AutoConfig.class)
60+
@EnumSource
6161
void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
6262
autoConfig.get().run((context) -> {
6363
Tracer tracer = tracer(context);
@@ -83,7 +83,7 @@ void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
8383
}
8484

8585
@ParameterizedTest
86-
@EnumSource(AutoConfig.class)
86+
@EnumSource
8787
void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {
8888
autoConfig.get().run((context) -> {
8989
Tracer tracer = tracer(context);

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontPropertiesTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -80,7 +80,7 @@ void wavefrontApiTokenTypeWhenNotUsingProxy() {
8080
}
8181

8282
@ParameterizedTest
83-
@EnumSource(TokenType.class)
83+
@EnumSource
8484
void wavefrontApiTokenMapping(TokenType from) {
8585
WavefrontProperties properties = new WavefrontProperties();
8686
properties.setApiTokenType(from);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/AcknowledgeModeTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 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.
@@ -32,7 +32,7 @@
3232
class AcknowledgeModeTests {
3333

3434
@ParameterizedTest
35-
@EnumSource(Mapping.class)
35+
@EnumSource
3636
void stringIsMappedToInt(Mapping mapping) {
3737
assertThat(AcknowledgeMode.of(mapping.actual)).extracting(AcknowledgeMode::getMode).isEqualTo(mapping.expected);
3838
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ void cacheCanBeCustomizedOnServletViewResolver() {
159159
}
160160

161161
@ParameterizedTest
162-
@EnumSource(ViewResolverKind.class)
162+
@EnumSource
163163
void charsetCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
164164
assertViewResolverProperty(kind, "spring.mustache.charset=UTF-16", "charset", "UTF-16");
165165
if (kind == ViewResolverKind.SERVLET) {
@@ -187,21 +187,21 @@ void exposeSpringMacroHelpersCanBeCustomizedOnServletViewResolver() {
187187
}
188188

189189
@ParameterizedTest
190-
@EnumSource(ViewResolverKind.class)
190+
@EnumSource
191191
void prefixCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
192192
assertViewResolverProperty(kind, "spring.mustache.prefix=classpath:/mustache-templates/", "prefix",
193193
"classpath:/mustache-templates/");
194194
}
195195

196196
@ParameterizedTest
197-
@EnumSource(ViewResolverKind.class)
197+
@EnumSource
198198
void requestContextAttributeCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
199199
assertViewResolverProperty(kind, "spring.mustache.request-context-attribute=test", "requestContextAttribute",
200200
"test");
201201
}
202202

203203
@ParameterizedTest
204-
@EnumSource(ViewResolverKind.class)
204+
@EnumSource
205205
void suffixCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
206206
assertViewResolverProperty(kind, "spring.mustache.suffix=.tache", "suffix", ".tache");
207207
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ void sessionCookieConfiguration() {
885885
}
886886

887887
@ParameterizedTest
888-
@EnumSource(SameSite.class)
888+
@EnumSource
889889
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
890890
AbstractServletWebServerFactory factory = getFactory();
891891
factory.getSession().getCookie().setSameSite(sameSite);
@@ -900,7 +900,7 @@ void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(S
900900
}
901901

902902
@ParameterizedTest
903-
@EnumSource(SameSite.class)
903+
@EnumSource
904904
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookiesWhenUsingCustomName(SameSite sameSite)
905905
throws Exception {
906906
AbstractServletWebServerFactory factory = getFactory();

0 commit comments

Comments
 (0)