Skip to content

Commit da74dd9

Browse files
committed
Merge branch '3.5.x'
Closes gh-47439
2 parents 1754e2e + c6311fe commit da74dd9

File tree

9 files changed

+153
-20
lines changed

9 files changed

+153
-20
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static List<ArchRule> standard() {
112112
rules.add(noClassesShouldCallStringToUpperCaseWithoutLocale());
113113
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
114114
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
115-
rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType());
115+
rules.add(enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter());
116116
rules.add(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
117117
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
118118
rules.add(conditionsShouldNotBePublic());
@@ -273,7 +273,7 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
273273
JavaAnnotation<JavaMethod> conditionalAnnotation = item
274274
.getAnnotationOfType("org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean");
275275
Map<String, Object> properties = conditionalAnnotation.getProperties();
276-
if (!properties.containsKey("type") && !properties.containsKey("name")) {
276+
if (!hasProperty("type", properties) && !hasProperty("name", properties)) {
277277
conditionalAnnotation.get("value").ifPresent((value) -> {
278278
if (containsOnlySingleType((JavaType[]) value, item.getReturnType())) {
279279
addViolation(events, item, conditionalAnnotation.getDescription()
@@ -284,32 +284,38 @@ private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSam
284284
});
285285
}
286286

287-
private static ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() {
287+
private static boolean hasProperty(String name, Map<String, Object> properties) {
288+
Object property = properties.get(name);
289+
if (property == null) {
290+
return false;
291+
}
292+
return !property.getClass().isArray() || ((Object[]) property).length > 0;
293+
}
294+
295+
private static ArchRule enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter() {
288296
return ArchRuleDefinition.methods()
289297
.that()
290298
.areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource")
291-
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType())
299+
.should(notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter())
292300
.allowEmptyShould(true);
293301
}
294302

295-
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType() {
296-
return check("not specify only a type that is the same as the method's parameter type",
303+
private static ArchCondition<? super JavaMethod> notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter() {
304+
return check("not have a value that is the same as the type of the method's first parameter",
297305
ArchitectureRules::notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType);
298306
}
299307

300308
private static void notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType(JavaMethod item,
301309
ConditionEvents events) {
302310
JavaAnnotation<JavaMethod> enumSourceAnnotation = item
303311
.getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource");
304-
Map<String, Object> properties = enumSourceAnnotation.getProperties();
305-
if (properties.size() == 1 && item.getParameterTypes().size() == 1) {
306-
enumSourceAnnotation.get("value").ifPresent((value) -> {
307-
if (value.equals(item.getParameterTypes().get(0))) {
308-
addViolation(events, item, enumSourceAnnotation.getDescription()
309-
+ " should not specify only a value that is the same as the method's parameter type");
310-
}
311-
});
312-
}
312+
enumSourceAnnotation.get("value").ifPresent((value) -> {
313+
JavaType parameterType = item.getParameterTypes().get(0);
314+
if (value.equals(parameterType)) {
315+
addViolation(events, item, enumSourceAnnotation.getDescription()
316+
+ " should not specify a value that is the same as the type of the method's first parameter");
317+
}
318+
});
313319
}
314320

315321
private static ArchRule classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute() {

buildSrc/src/test/java/org/springframework/boot/build/architecture/ArchitectureCheckTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class ArchitectureCheckTests {
5757

5858
private static final String SPRING_CONTEXT = "org.springframework:spring-context:6.2.9";
5959

60+
private static final String JUNIT_JUPITER = "org.junit.jupiter:junit-jupiter:5.12.0";
61+
6062
private static final String SPRING_INTEGRATION_JMX = "org.springframework.integration:spring-integration-jmx:6.5.1";
6163

6264
private GradleBuild gradleBuild;
@@ -283,6 +285,29 @@ void whenPackageIsNotAnnotatedWithNullMarkedWithTestSourcesShouldSucceedAndWrite
283285
build(this.gradleBuild.withNullMarked(true), Task.CHECK_ARCHITECTURE_TEST);
284286
}
285287

288+
@Test
289+
void whenEnumSourceValueIsInferredShouldSucceedAndWriteEmptyReport() throws IOException {
290+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/inferredfromparametertype");
291+
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
292+
}
293+
294+
@Test
295+
void whenEnumSourceValueIsNotTheSameAsTypeOfMethodsFirstParameterShouldSucceedAndWriteEmptyReport()
296+
throws IOException {
297+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/valuenecessary");
298+
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
299+
}
300+
301+
@Test
302+
void whenEnumSourceValueIsSameAsTypeOfMethodsFirstParameterShouldFailAndWriteReport() throws IOException {
303+
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/sameasparametertype");
304+
buildAndFail(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST,
305+
"method <org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype"
306+
+ ".EnumSourceSameAsParameterType.exampleMethod(org.springframework.boot.build."
307+
+ "architecture.junit.enumsource.sameasparametertype.EnumSourceSameAsParameterType$Example)>",
308+
"should not have a value that is the same as the type of the method's first parameter");
309+
}
310+
286311
private void prepareTask(Task task, String... sourceDirectories) throws IOException {
287312
for (String sourceDirectory : sourceDirectories) {
288313
FileSystemUtils.copyRecursively(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.inferredfromparametertype;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceInferredFromParameterType {
22+
23+
@EnumSource
24+
void exampleMethod(Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceSameAsParameterType {
22+
23+
@EnumSource(Example.class)
24+
void exampleMethod(Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.build.architecture.junit.enumsource.valuenecessary;
18+
19+
import org.junit.jupiter.params.provider.EnumSource;
20+
21+
class EnumSourceValueNecessary {
22+
23+
@EnumSource(Example.class)
24+
void exampleMethod(String thing, Example example) {
25+
26+
}
27+
28+
enum Example {
29+
30+
ONE, TWO, THREE
31+
32+
}
33+
34+
}

module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/sbom/SbomEndpointWebExtensionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void shouldUseContentTypeForAdditionalSbomsIfSet() {
112112
}
113113

114114
@ParameterizedTest
115-
@EnumSource(value = SbomType.class, names = "UNKNOWN", mode = Mode.EXCLUDE)
115+
@EnumSource(names = "UNKNOWN", mode = Mode.EXCLUDE)
116116
void shouldAutodetectFormats(SbomType type) throws IOException {
117117
String content = getSbomContent(type);
118118
assertThat(type.matches(content)).isTrue();

module/spring-boot-batch-jdbc/src/test/java/org/springframework/boot/batch/jdbc/autoconfigure/BatchDataSourceScriptDatabaseInitializerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ void getSettingsWithPlatformDoesNotTouchDataSource() {
6262
}
6363

6464
@ParameterizedTest
65-
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD",
66-
"INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
65+
@EnumSource(mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD", "INFORMIX", "JTDS", "PHOENIX",
66+
"REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
6767
void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException {
6868
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
6969
BatchJdbcProperties properties = new BatchJdbcProperties();

module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private void customize(JsonMapper.Builder builder, List<JsonMapperBuilderCustomi
111111

112112
@Bean
113113
@Primary
114-
@ConditionalOnMissingBean(JsonMapper.class)
114+
@ConditionalOnMissingBean
115115
JsonMapper jacksonJsonMapper(JsonMapper.Builder builder) {
116116
return builder.build();
117117
}

module/spring-boot-jms/src/main/java/org/springframework/boot/jms/autoconfigure/JmsClientConfigurations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private void mapTemplateProperties(Template properties, JmsMessagingTemplate mes
120120
static class JmsClientConfiguration {
121121

122122
@Bean
123-
@ConditionalOnMissingBean(JmsClient.class)
123+
@ConditionalOnMissingBean
124124
@ConditionalOnSingleCandidate(JmsTemplate.class)
125125
JmsClient jmsClient(JmsTemplate jmsTemplate) {
126126
return JmsClient.create(jmsTemplate);

0 commit comments

Comments
 (0)