-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix enums as each property keys. Fixes #10944
- Loading branch information
1 parent
d247e9d
commit 22aab3d
Showing
3 changed files
with
55 additions
and
5 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
inject-java/src/test/groovy/io/micronaut/inject/foreach/withenum/EnumConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.micronaut.inject.foreach.withenum; | ||
|
||
import io.micronaut.context.annotation.EachProperty; | ||
import io.micronaut.context.annotation.Parameter; | ||
import io.micronaut.context.annotation.Requires; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import java.util.List; | ||
|
||
@EachProperty("enumconfig") | ||
@Requires(property = "enumconfig") | ||
public record EnumConfiguration(@Parameter MyEnum myEnum, | ||
@NotEmpty List<@NotBlank String> cities) { | ||
|
||
public enum MyEnum { | ||
SUMMER, | ||
WINTER | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
inject-java/src/test/groovy/io/micronaut/inject/foreach/withenum/EnumEachPropertySpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.micronaut.inject.foreach.withenum | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.inject.qualifiers.Qualifiers | ||
import spock.lang.Specification | ||
|
||
class EnumEachPropertySpec extends Specification { | ||
|
||
void "test each property with enum keys"() { | ||
given: | ||
def ctx = ApplicationContext.run( | ||
"enumconfig.summer.cities":"barcelona,atlanta,sydney", | ||
"enumconfig.winter.cities": "albertville,lillehammer,nagano" | ||
) | ||
|
||
when: | ||
EnumConfiguration configuration = ctx.getBean(EnumConfiguration, Qualifiers.byName(EnumConfiguration.MyEnum.SUMMER.name())) | ||
|
||
then: | ||
configuration != null | ||
configuration.myEnum() == EnumConfiguration.MyEnum.SUMMER | ||
|
||
|
||
cleanup: | ||
ctx.close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters