Skip to content

Commit

Permalink
Test for optional Map values
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Oct 15, 2024
1 parent 1e7134a commit 4d235b6
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2659,4 +2659,28 @@ interface Nested {
String value();
}
}

@Test
void optionalMapValue() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(config("map.map.key", "value", "map.map.empty", ""))
.withMapping(OptionalMapValue.class)
.build();

OptionalMapValue mapping = config.getConfigMapping(OptionalMapValue.class);
assertTrue(mapping.map().get("key").value().isPresent());
assertEquals("value", mapping.map().get("key").value().get());
assertTrue(mapping.map().containsKey("empty"));
assertFalse(mapping.map().get("empty").value().isPresent());
}

@ConfigMapping(prefix = "map")
interface OptionalMapValue {
Map<String, Value> map();

interface Value {
@WithParentName
Optional<String> value();
}
}
}

0 comments on commit 4d235b6

Please sign in to comment.