Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public ArchitectureCheck() {
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()));
Expand Down Expand Up @@ -299,6 +300,35 @@ public void check(JavaMethod item, ConditionEvents events) {
};
}

private ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() {
return ArchRuleDefinition.methods()
.that()
.areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource")
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType())
.allowEmptyShould(true);
}

private ArchCondition<? super JavaMethod> 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<JavaMethod> conditional = item
.getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource");
Map<String, Object> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void setup() {
}

@ParameterizedTest
@EnumSource(AutoConfig.class)
@EnumSource
void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
autoConfig.get().run((context) -> {
Tracer tracer = tracer(context);
Expand All @@ -87,7 +87,7 @@ void shouldSetEntriesToMdcFromSpanWithBaggage(AutoConfig autoConfig) {
}

@ParameterizedTest
@EnumSource(AutoConfig.class)
@EnumSource
void shouldRemoveEntriesFromMdcForNullSpan(AutoConfig autoConfig) {
autoConfig.get().run((context) -> {
Tracer tracer = tracer(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -80,7 +80,7 @@ void wavefrontApiTokenTypeWhenNotUsingProxy() {
}

@ParameterizedTest
@EnumSource(TokenType.class)
@EnumSource
void wavefrontApiTokenMapping(TokenType from) {
WavefrontProperties properties = new WavefrontProperties();
properties.setApiTokenType(from);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -32,7 +32,7 @@
class AcknowledgeModeTests {

@ParameterizedTest
@EnumSource(Mapping.class)
@EnumSource
void stringIsMappedToInt(Mapping mapping) {
assertThat(AcknowledgeMode.of(mapping.actual)).extracting(AcknowledgeMode::getMode).isEqualTo(mapping.expected);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -158,7 +158,7 @@ void cacheCanBeCustomizedOnServletViewResolver() {
}

@ParameterizedTest
@EnumSource(ViewResolverKind.class)
@EnumSource
void charsetCanBeCustomizedOnViewResolver(ViewResolverKind kind) {
assertViewResolverProperty(kind, "spring.mustache.charset=UTF-16", "charset", "UTF-16");
}
Expand All @@ -182,21 +182,21 @@ void exposeSpringMacroHelpersCanBeCustomizedOnServletViewResolver() {
}

@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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ void sessionCookieConfiguration() {
}

@ParameterizedTest
@EnumSource(SameSite.class)
@EnumSource
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(SameSite sameSite) throws Exception {
AbstractServletWebServerFactory factory = getFactory();
factory.getSession().getCookie().setSameSite(sameSite);
Expand All @@ -886,7 +886,7 @@ void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookies(S
}

@ParameterizedTest
@EnumSource(SameSite.class)
@EnumSource
void sessionCookieSameSiteAttributeCanBeConfiguredAndOnlyAffectsSessionCookiesWhenUsingCustomName(SameSite sameSite)
throws Exception {
AbstractServletWebServerFactory factory = getFactory();
Expand Down