Skip to content

Commit 86d08fb

Browse files
committed
Merge pull request #44747 from quaff
* pr/44747: Udate copyright year of changed file Remove workaround for Java Records in tests Closes gh-44747
2 parents af13323 + 19de226 commit 86d08fb

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ValueObjectBinderTests.java

+11-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,21 +36,19 @@
3636
import org.springframework.core.DefaultParameterNameDiscoverer;
3737
import org.springframework.core.ResolvableType;
3838
import org.springframework.core.convert.ConversionService;
39-
import org.springframework.core.test.tools.SourceFile;
40-
import org.springframework.core.test.tools.TestCompiler;
4139
import org.springframework.format.annotation.DateTimeFormat;
4240
import org.springframework.util.Assert;
4341

4442
import static org.assertj.core.api.Assertions.assertThat;
4543
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
46-
import static org.assertj.core.api.Assertions.fail;
4744

4845
/**
4946
* Tests for {@link ValueObjectBinder}.
5047
*
5148
* @author Madhura Bhave
5249
* @author Phillip Webb
5350
* @author Pavel Anisimov
51+
* @author Yanming Zhou
5452
*/
5553
class ValueObjectBinderTests {
5654

@@ -390,25 +388,12 @@ void bindToAnnotationNamedRecordComponent() {
390388
@Test
391389
void bindToRecordWithDefaultValue() {
392390
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
393-
source.put("test.record.property1", "value-from-config-1");
391+
source.put("test.property1", "value-from-config-1");
394392
this.sources.add(source);
395-
String recordProperties = """
396-
public record RecordProperties(
397-
@org.springframework.boot.context.properties.bind.DefaultValue("default-value-1") String property1,
398-
@org.springframework.boot.context.properties.bind.DefaultValue("default-value-2") String property2) {
399-
}
400-
""";
401-
TestCompiler.forSystem().withSources(SourceFile.of(recordProperties)).compile((compiled) -> {
402-
try {
403-
ClassLoader cl = compiled.getClassLoader();
404-
Object bean = this.binder.bind("test.record", Class.forName("RecordProperties", true, cl)).get();
405-
assertThat(bean).hasFieldOrPropertyWithValue("property1", "value-from-config-1")
406-
.hasFieldOrPropertyWithValue("property2", "default-value-2");
407-
}
408-
catch (ClassNotFoundException ex) {
409-
fail("Expected generated class 'RecordProperties' not found", ex);
410-
}
411-
});
393+
Bindable<RecordProperties> target = Bindable.of(RecordProperties.class);
394+
RecordProperties bound = this.binder.bindOrCreate("test", target);
395+
assertThat(bound.property1()).isEqualTo("value-from-config-1");
396+
assertThat(bound.property2()).isEqualTo("default-value-2");
412397
}
413398

414399
@Test // gh-38201
@@ -912,6 +897,10 @@ String getImportName() {
912897
record NamedRecordComponent(@Name("import") String importName) {
913898
}
914899

900+
record RecordProperties(@DefaultValue("default-value-1") String property1,
901+
@DefaultValue("default-value-2") String property2) {
902+
}
903+
915904
static class NonExtractableParameterName {
916905

917906
private String value;

0 commit comments

Comments
 (0)