Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* @author Pavel Anisimov
* @author Scott Frederick
* @author Moritz Halbritter
* @author Yanming Zhou
*/
class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGenerationTests {

Expand Down Expand Up @@ -492,6 +493,32 @@ public record ExampleRecord(String someString, Integer someInteger) {
assertThat(metadata).has(Metadata.withProperty("implicit.some-integer"));
}

@Test
void recordPropertiesWithName() {
String source = """
@org.springframework.boot.configurationsample.ConfigurationProperties("implicit")
public record ExampleRecord(
@org.springframework.boot.configurationsample.Name("for") String forString) {
}
""";
ConfigurationMetadata metadata = compile(source);
assertThat(metadata).has(Metadata.withProperty("implicit.for"));
}

@Test
void recordPropertiesWithNameAndDefaultValue() {
String source = """
@org.springframework.boot.configurationsample.ConfigurationProperties("implicit")
public record ExampleRecord(
@org.springframework.boot.configurationsample.Name("for")
@org.springframework.boot.configurationsample.DefaultValue("example")
String forString) {
}
""";
ConfigurationMetadata metadata = compile(source);
assertThat(metadata).has(Metadata.withProperty("implicit.for", String.class).withDefaultValue("example"));
}

@Test
void recordPropertiesWithDefaultValues() {
String source = """
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -27,8 +27,9 @@
* dependency on the real annotation).
*
* @author Phillip Webb
* @author Yanming Zhou
*/
@Target({ ElementType.PARAMETER, ElementType.FIELD })
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Name {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -32,10 +32,11 @@
*
* @author Phillip Webb
* @author Lasse Wulff
* @author Yanming Zhou
* @since 2.4.0
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.FIELD, ElementType.PARAMETER })
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.RECORD_COMPONENT })
@Documented
public @interface Name {

Expand Down