diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java index 7c96251c7f2..d1d830d60e6 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureCheck.java @@ -94,7 +94,8 @@ public abstract class ArchitectureCheck extends DefaultTask { noClassesShouldCallURLEncoderWithStringEncoding(), noClassesShouldCallURLDecoderWithStringEncoding(), noClassesShouldLoadResourcesUsingResourceUtils(), noClassesShouldCallStringToUpperCaseWithoutLocale(), noClassesShouldCallStringToLowerCaseWithoutLocale(), - conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType()); + conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType(), + enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType()); getRules().addAll(getProhibitObjectsRequireNonNull() .map((prohibit) -> prohibit ? noClassesShouldCallObjectsRequireNonNull() : Collections.emptyList())); getRuleDescriptions().set(getRules().map((rules) -> rules.stream().map(ArchRule::getDescription).toList())); @@ -299,6 +300,35 @@ public abstract class ArchitectureCheck extends DefaultTask { }; } + private ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() { + return ArchRuleDefinition.methods() + .that() + .areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource") + .should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType()) + .allowEmptyShould(true); + } + + private ArchCondition notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType() { + return new ArchCondition<>("not specify only a type that is the same as the method's parameter type") { + + @Override + public void check(JavaMethod item, ConditionEvents events) { + JavaAnnotation conditional = item + .getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource"); + Map properties = conditional.getProperties(); + if (properties.size() == 1 && item.getParameterTypes().size() == 1) { + conditional.get("value").ifPresent((value) -> { + if (value.equals(item.getParameterTypes().get(0))) { + events.add(SimpleConditionEvent.violated(item, conditional.getDescription() + + " should not specify only a value that is the same as the method's parameter type")); + } + }); + } + } + + }; + } + public void setClasses(FileCollection classes) { this.classes = classes; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java index 61681e3428c..ae70c4cb9ef 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/tracing/BaggagePropagationIntegrationTests.java @@ -61,7 +61,7 @@ class BaggagePropagationIntegrationTests { } @ParameterizedTest - @EnumSource(AutoConfig.class) + @EnumSource void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) { autoConfig.get().run((context) -> { Tracer tracer = tracer(context); @@ -87,7 +87,7 @@ class BaggagePropagationIntegrationTests { } @ParameterizedTest - @EnumSource(AutoConfig.class) + @EnumSource void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) { autoConfig.get().run((context) -> { Tracer tracer = tracer(context); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontPropertiesTests.java index b9aaca91439..719861b5da8 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/wavefront/WavefrontPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,7 +80,7 @@ class WavefrontPropertiesTests { } @ParameterizedTest - @EnumSource(TokenType.class) + @EnumSource void wavefrontApiTokenMapping(TokenType from) { WavefrontProperties properties = new WavefrontProperties(); properties.setApiTokenType(from); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/AcknowledgeModeTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/AcknowledgeModeTests.java index 77957f5a967..cf785f75065 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/AcknowledgeModeTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/AcknowledgeModeTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class AcknowledgeModeTests { @ParameterizedTest - @EnumSource(Mapping.class) + @EnumSource void stringIsMappedToInt(Mapping mapping) { assertThat(AcknowledgeMode.of(mapping.actual)).extracting(AcknowledgeMode::getMode).isEqualTo(mapping.expected); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java index 7d1d54fc1da..4a254fe1794 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -158,7 +158,7 @@ class MustacheAutoConfigurationTests { } @ParameterizedTest - @EnumSource(ViewResolverKind.class) + @EnumSource void charsetCanBeCustomizedOnViewResolver(ViewResolverKind kind) { assertViewResolverProperty(kind, "spring.mustache.charset=UTF-16", "charset", "UTF-16"); } @@ -182,21 +182,21 @@ class MustacheAutoConfigurationTests { } @ParameterizedTest - @EnumSource(ViewResolverKind.class) + @EnumSource void prefixCanBeCustomizedOnViewResolver(ViewResolverKind kind) { assertViewResolverProperty(kind, "spring.mustache.prefix=classpath:/mustache-templates/", "prefix", "classpath:/mustache-templates/"); } @ParameterizedTest - @EnumSource(ViewResolverKind.class) + @EnumSource void requestContextAttributeCanBeCustomizedOnViewResolver(ViewResolverKind kind) { assertViewResolverProperty(kind, "spring.mustache.request-context-attribute=test", "requestContextAttribute", "test"); } @ParameterizedTest - @EnumSource(ViewResolverKind.class) + @EnumSource void suffixCanBeCustomizedOnViewResolver(ViewResolverKind kind) { assertViewResolverProperty(kind, "spring.mustache.suffix=.tache", "suffix", ".tache"); } diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java index 1659290e106..35db53301b4 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java @@ -871,7 +871,7 @@ public abstract class AbstractServletWebServerFactoryTests { } @ParameterizedTest - @EnumSource(SameSite.class) + @EnumSource void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception { AbstractServletWebServerFactory factory = getFactory(); factory.getSession().getCookie().setSameSite(sameSite); @@ -886,7 +886,7 @@ public abstract class AbstractServletWebServerFactoryTests { } @ParameterizedTest - @EnumSource(SameSite.class) + @EnumSource void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookiesWhenUsingCustomName(SameSite sameSite) throws Exception { AbstractServletWebServerFactory factory = getFactory();