parent
d9c2e7c85a
commit
fbb060e0fe
|
|
@ -410,41 +410,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
|||
}
|
||||
|
||||
@Test
|
||||
void explicityBoundRecordProperties(@TempDir File temp) throws IOException {
|
||||
File exampleRecord = new File(temp, "ExampleRecord.java");
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) {
|
||||
writer.println("@org.springframework.boot.configurationsample.ConstructorBinding");
|
||||
writer.println("@org.springframework.boot.configurationsample.ConfigurationProperties(\"explicit\")");
|
||||
writer.println("public record ExampleRecord(String someString, Integer someInteger) {");
|
||||
writer.println("}");
|
||||
}
|
||||
ConfigurationMetadata metadata = compile(exampleRecord);
|
||||
assertThat(metadata).has(Metadata.withProperty("explicit.some-string"));
|
||||
assertThat(metadata).has(Metadata.withProperty("explicit.some-integer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitlyBoundRecordPropertiesWithDefaultValues(@TempDir File temp) throws IOException {
|
||||
File exampleRecord = new File(temp, "ExampleRecord.java");
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) {
|
||||
writer.println("@org.springframework.boot.configurationsample.ConstructorBinding");
|
||||
writer.println(
|
||||
"@org.springframework.boot.configurationsample.ConfigurationProperties(\"record.defaults\")");
|
||||
writer.println("public record ExampleRecord(");
|
||||
writer.println("@org.springframework.boot.configurationsample.DefaultValue(\"An1s9n\") String someString,");
|
||||
writer.println("@org.springframework.boot.configurationsample.DefaultValue(\"594\") Integer someInteger");
|
||||
writer.println(") {");
|
||||
writer.println("}");
|
||||
}
|
||||
ConfigurationMetadata metadata = compile(exampleRecord);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("record.defaults.some-string", String.class).withDefaultValue("An1s9n"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("record.defaults.some-integer", Integer.class).withDefaultValue(594));
|
||||
}
|
||||
|
||||
@Test
|
||||
void implicitlyBoundRecordProperties(@TempDir File temp) throws IOException {
|
||||
void recordProperties(@TempDir File temp) throws IOException {
|
||||
File exampleRecord = new File(temp, "ExampleRecord.java");
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) {
|
||||
writer.println("@org.springframework.boot.configurationsample.ConfigurationProperties(\"implicit\")");
|
||||
|
|
@ -457,7 +423,7 @@ class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGene
|
|||
}
|
||||
|
||||
@Test
|
||||
void implicitlyBoundRecordPropertiesWithDefaultValues(@TempDir File temp) throws IOException {
|
||||
void recordPropertiesWithDefaultValues(@TempDir File temp) throws IOException {
|
||||
File exampleRecord = new File(temp, "ExampleRecord.java");
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) {
|
||||
writer.println(
|
||||
|
|
|
|||
|
|
@ -223,32 +223,7 @@ class ConfigurationPropertiesBeanTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void forValueObjectWithConstructorBindingAnnotatedRecordReturnsBean() {
|
||||
Class<?> constructorBindingRecord = new ByteBuddy(ClassFileVersion.JAVA_V16).makeRecord()
|
||||
.name("org.springframework.boot.context.properties.RecordProperties")
|
||||
.annotateType(AnnotationDescription.Builder.ofType(ConfigurationProperties.class)
|
||||
.define("prefix", "explicit").build())
|
||||
.annotateType(AnnotationDescription.Builder.ofType(ConstructorBinding.class).build())
|
||||
.defineRecordComponent("someString", String.class).defineRecordComponent("someInteger", Integer.class)
|
||||
.make().load(getClass().getClassLoader()).getLoaded();
|
||||
ConfigurationPropertiesBean propertiesBean = ConfigurationPropertiesBean
|
||||
.forValueObject(constructorBindingRecord, "constructorBindingRecord");
|
||||
assertThat(propertiesBean.getName()).isEqualTo("constructorBindingRecord");
|
||||
assertThat(propertiesBean.getInstance()).isNull();
|
||||
assertThat(propertiesBean.getType()).isEqualTo(constructorBindingRecord);
|
||||
assertThat(propertiesBean.getBindMethod()).isEqualTo(BindMethod.VALUE_OBJECT);
|
||||
assertThat(propertiesBean.getAnnotation()).isNotNull();
|
||||
Bindable<?> target = propertiesBean.asBindTarget();
|
||||
assertThat(target.getType()).isEqualTo(ResolvableType.forClass(constructorBindingRecord));
|
||||
assertThat(target.getValue()).isNull();
|
||||
Constructor<?> bindConstructor = ConfigurationPropertiesBindConstructorProvider.INSTANCE
|
||||
.getBindConstructor(constructorBindingRecord, false);
|
||||
assertThat(bindConstructor).isNotNull();
|
||||
assertThat(bindConstructor.getParameterTypes()).containsExactly(String.class, Integer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void forValueObjectWithUnannotatedRecordReturnsBean() {
|
||||
void forValueObjectWithRecordReturnsBean() {
|
||||
Class<?> implicitConstructorBinding = new ByteBuddy(ClassFileVersion.JAVA_V16).makeRecord()
|
||||
.name("org.springframework.boot.context.properties.ImplicitConstructorBinding")
|
||||
.annotateType(AnnotationDescription.Builder.ofType(ConfigurationProperties.class)
|
||||
|
|
|
|||
Loading…
Reference in New Issue