|
16 | 16 |
|
17 | 17 | package org.springframework.boot.configurationprocessor;
|
18 | 18 |
|
| 19 | +import java.io.File; |
| 20 | +import java.io.FileWriter; |
| 21 | +import java.io.IOException; |
| 22 | +import java.io.PrintWriter; |
| 23 | + |
19 | 24 | import org.junit.jupiter.api.Test;
|
| 25 | +import org.junit.jupiter.api.condition.EnabledForJreRange; |
| 26 | +import org.junit.jupiter.api.condition.JRE; |
| 27 | +import org.junit.jupiter.api.io.TempDir; |
20 | 28 |
|
21 | 29 | import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
|
22 | 30 | import org.springframework.boot.configurationprocessor.metadata.ItemMetadata;
|
@@ -402,4 +410,54 @@ void recursivePropertiesDoNotCauseAStackOverflow() {
|
402 | 410 | compile(RecursiveProperties.class);
|
403 | 411 | }
|
404 | 412 |
|
| 413 | + @Test |
| 414 | + @EnabledForJreRange(min = JRE.JAVA_16) |
| 415 | + void explicityBoundRecordProperties(@TempDir File temp) throws IOException { |
| 416 | + File exampleRecord = new File(temp, "ExampleRecord.java"); |
| 417 | + try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) { |
| 418 | + writer.println("@org.springframework.boot.configurationsample.ConstructorBinding"); |
| 419 | + writer.println("@org.springframework.boot.configurationsample.ConfigurationProperties(\"explicit\")"); |
| 420 | + writer.println("public record ExampleRecord(String someString, Integer someInteger) {"); |
| 421 | + writer.println("}"); |
| 422 | + } |
| 423 | + ConfigurationMetadata metadata = compile(exampleRecord); |
| 424 | + assertThat(metadata).has(Metadata.withProperty("explicit.some-string")); |
| 425 | + assertThat(metadata).has(Metadata.withProperty("explicit.some-integer")); |
| 426 | + } |
| 427 | + |
| 428 | + @Test |
| 429 | + @EnabledForJreRange(min = JRE.JAVA_16) |
| 430 | + void implicitlyBoundRecordProperties(@TempDir File temp) throws IOException { |
| 431 | + File exampleRecord = new File(temp, "ExampleRecord.java"); |
| 432 | + try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) { |
| 433 | + writer.println("@org.springframework.boot.configurationsample.ConfigurationProperties(\"implicit\")"); |
| 434 | + writer.println("public record ExampleRecord(String someString, Integer someInteger) {"); |
| 435 | + writer.println("}"); |
| 436 | + } |
| 437 | + ConfigurationMetadata metadata = compile(exampleRecord); |
| 438 | + assertThat(metadata).has(Metadata.withProperty("implicit.some-string")); |
| 439 | + assertThat(metadata).has(Metadata.withProperty("implicit.some-integer")); |
| 440 | + } |
| 441 | + |
| 442 | + @Test |
| 443 | + @EnabledForJreRange(min = JRE.JAVA_16) |
| 444 | + void multiConstructorRecordProperties(@TempDir File temp) throws IOException { |
| 445 | + File exampleRecord = new File(temp, "ExampleRecord.java"); |
| 446 | + try (PrintWriter writer = new PrintWriter(new FileWriter(exampleRecord))) { |
| 447 | + writer.println("@org.springframework.boot.configurationsample.ConfigurationProperties(\"multi\")"); |
| 448 | + writer.println("public record ExampleRecord(String someString, Integer someInteger) {"); |
| 449 | + writer.println(" @org.springframework.boot.configurationsample.ConstructorBinding"); |
| 450 | + writer.println(" public ExampleRecord(String someString) {"); |
| 451 | + writer.println(" this(someString, 42);"); |
| 452 | + writer.println(" }"); |
| 453 | + writer.println(" public ExampleRecord(Integer someInteger) {"); |
| 454 | + writer.println(" this(\"someString\", someInteger);"); |
| 455 | + writer.println(" }"); |
| 456 | + writer.println("}"); |
| 457 | + } |
| 458 | + ConfigurationMetadata metadata = compile(exampleRecord); |
| 459 | + assertThat(metadata).has(Metadata.withProperty("multi.some-string")); |
| 460 | + assertThat(metadata).doesNotHave(Metadata.withProperty("multi.some-integer")); |
| 461 | + } |
| 462 | + |
405 | 463 | }
|
0 commit comments