mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-01 23:09:01 +00:00
Merge branch '3.5.x'
Closes gh-47439
This commit is contained in:
+21
-15
@@ -112,7 +112,7 @@ final class ArchitectureRules {
|
||||
rules.add(noClassesShouldCallStringToUpperCaseWithoutLocale());
|
||||
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
|
||||
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
|
||||
rules.add(enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType());
|
||||
rules.add(enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter());
|
||||
rules.add(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
|
||||
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
|
||||
rules.add(conditionsShouldNotBePublic());
|
||||
@@ -273,7 +273,7 @@ final class ArchitectureRules {
|
||||
JavaAnnotation<JavaMethod> conditionalAnnotation = item
|
||||
.getAnnotationOfType("org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean");
|
||||
Map<String, Object> properties = conditionalAnnotation.getProperties();
|
||||
if (!properties.containsKey("type") && !properties.containsKey("name")) {
|
||||
if (!hasProperty("type", properties) && !hasProperty("name", properties)) {
|
||||
conditionalAnnotation.get("value").ifPresent((value) -> {
|
||||
if (containsOnlySingleType((JavaType[]) value, item.getReturnType())) {
|
||||
addViolation(events, item, conditionalAnnotation.getDescription()
|
||||
@@ -284,16 +284,24 @@ final class ArchitectureRules {
|
||||
});
|
||||
}
|
||||
|
||||
private static ArchRule enumSourceShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodParameterType() {
|
||||
private static boolean hasProperty(String name, Map<String, Object> properties) {
|
||||
Object property = properties.get(name);
|
||||
if (property == null) {
|
||||
return false;
|
||||
}
|
||||
return !property.getClass().isArray() || ((Object[]) property).length > 0;
|
||||
}
|
||||
|
||||
private static ArchRule enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter() {
|
||||
return ArchRuleDefinition.methods()
|
||||
.that()
|
||||
.areAnnotatedWith("org.junit.jupiter.params.provider.EnumSource")
|
||||
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType())
|
||||
.should(notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter())
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType() {
|
||||
return check("not specify only a type that is the same as the method's parameter type",
|
||||
private static ArchCondition<? super JavaMethod> notHaveValueThatIsTheSameAsTheTypeOfTheMethodsFirstParameter() {
|
||||
return check("not have a value that is the same as the type of the method's first parameter",
|
||||
ArchitectureRules::notSpecifyOnlyATypeThatIsTheSameAsTheMethodParameterType);
|
||||
}
|
||||
|
||||
@@ -301,15 +309,13 @@ final class ArchitectureRules {
|
||||
ConditionEvents events) {
|
||||
JavaAnnotation<JavaMethod> enumSourceAnnotation = item
|
||||
.getAnnotationOfType("org.junit.jupiter.params.provider.EnumSource");
|
||||
Map<String, Object> properties = enumSourceAnnotation.getProperties();
|
||||
if (properties.size() == 1 && item.getParameterTypes().size() == 1) {
|
||||
enumSourceAnnotation.get("value").ifPresent((value) -> {
|
||||
if (value.equals(item.getParameterTypes().get(0))) {
|
||||
addViolation(events, item, enumSourceAnnotation.getDescription()
|
||||
+ " should not specify only a value that is the same as the method's parameter type");
|
||||
}
|
||||
});
|
||||
}
|
||||
enumSourceAnnotation.get("value").ifPresent((value) -> {
|
||||
JavaType parameterType = item.getParameterTypes().get(0);
|
||||
if (value.equals(parameterType)) {
|
||||
addViolation(events, item, enumSourceAnnotation.getDescription()
|
||||
+ " should not specify a value that is the same as the type of the method's first parameter");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ArchRule classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute() {
|
||||
|
||||
+25
@@ -57,6 +57,8 @@ class ArchitectureCheckTests {
|
||||
|
||||
private static final String SPRING_CONTEXT = "org.springframework:spring-context:6.2.9";
|
||||
|
||||
private static final String JUNIT_JUPITER = "org.junit.jupiter:junit-jupiter:5.12.0";
|
||||
|
||||
private static final String SPRING_INTEGRATION_JMX = "org.springframework.integration:spring-integration-jmx:6.5.1";
|
||||
|
||||
private GradleBuild gradleBuild;
|
||||
@@ -283,6 +285,29 @@ class ArchitectureCheckTests {
|
||||
build(this.gradleBuild.withNullMarked(true), Task.CHECK_ARCHITECTURE_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEnumSourceValueIsInferredShouldSucceedAndWriteEmptyReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/inferredfromparametertype");
|
||||
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEnumSourceValueIsNotTheSameAsTypeOfMethodsFirstParameterShouldSucceedAndWriteEmptyReport()
|
||||
throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/valuenecessary");
|
||||
build(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenEnumSourceValueIsSameAsTypeOfMethodsFirstParameterShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "junit/enumsource/sameasparametertype");
|
||||
buildAndFail(this.gradleBuild.withDependencies(JUNIT_JUPITER), Task.CHECK_ARCHITECTURE_TEST,
|
||||
"method <org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype"
|
||||
+ ".EnumSourceSameAsParameterType.exampleMethod(org.springframework.boot.build."
|
||||
+ "architecture.junit.enumsource.sameasparametertype.EnumSourceSameAsParameterType$Example)>",
|
||||
"should not have a value that is the same as the type of the method's first parameter");
|
||||
}
|
||||
|
||||
private void prepareTask(Task task, String... sourceDirectories) throws IOException {
|
||||
for (String sourceDirectory : sourceDirectories) {
|
||||
FileSystemUtils.copyRecursively(
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.architecture.junit.enumsource.inferredfromparametertype;
|
||||
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
class EnumSourceInferredFromParameterType {
|
||||
|
||||
@EnumSource
|
||||
void exampleMethod(Example example) {
|
||||
|
||||
}
|
||||
|
||||
enum Example {
|
||||
|
||||
ONE, TWO, THREE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.architecture.junit.enumsource.sameasparametertype;
|
||||
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
class EnumSourceSameAsParameterType {
|
||||
|
||||
@EnumSource(Example.class)
|
||||
void exampleMethod(Example example) {
|
||||
|
||||
}
|
||||
|
||||
enum Example {
|
||||
|
||||
ONE, TWO, THREE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.architecture.junit.enumsource.valuenecessary;
|
||||
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
class EnumSourceValueNecessary {
|
||||
|
||||
@EnumSource(Example.class)
|
||||
void exampleMethod(String thing, Example example) {
|
||||
|
||||
}
|
||||
|
||||
enum Example {
|
||||
|
||||
ONE, TWO, THREE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -112,7 +112,7 @@ class SbomEndpointWebExtensionTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = SbomType.class, names = "UNKNOWN", mode = Mode.EXCLUDE)
|
||||
@EnumSource(names = "UNKNOWN", mode = Mode.EXCLUDE)
|
||||
void shouldAutodetectFormats(SbomType type) throws IOException {
|
||||
String content = getSbomContent(type);
|
||||
assertThat(type.matches(content)).isTrue();
|
||||
|
||||
+2
-2
@@ -62,8 +62,8 @@ class BatchDataSourceScriptDatabaseInitializerTests {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = DatabaseDriver.class, mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD",
|
||||
"INFORMIX", "JTDS", "PHOENIX", "REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
|
||||
@EnumSource(mode = Mode.EXCLUDE, names = { "AWS_WRAPPER", "CLICKHOUSE", "FIREBIRD", "INFORMIX", "JTDS", "PHOENIX",
|
||||
"REDSHIFT", "TERADATA", "TESTCONTAINERS", "UNKNOWN" })
|
||||
void batchSchemaCanBeLocated(DatabaseDriver driver) throws SQLException {
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
BatchJdbcProperties properties = new BatchJdbcProperties();
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ public final class JacksonAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@Primary
|
||||
@ConditionalOnMissingBean(JsonMapper.class)
|
||||
@ConditionalOnMissingBean
|
||||
JsonMapper jacksonJsonMapper(JsonMapper.Builder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ abstract class JmsClientConfigurations {
|
||||
static class JmsClientConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(JmsClient.class)
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnSingleCandidate(JmsTemplate.class)
|
||||
JmsClient jmsClient(JmsTemplate jmsTemplate) {
|
||||
return JmsClient.create(jmsTemplate);
|
||||
|
||||
Reference in New Issue
Block a user