Skip to content

Commit

Permalink
Merge external map properties (#1656)
Browse files Browse the repository at this point in the history
Fixes #874
  • Loading branch information
maciejwalkowiak authored Aug 18, 2021
1 parent fd71717 commit d9f2498
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

* Feat: Merge external map properties (#1656)

## 5.1.0

* Feat: Spring WebClient integration (#1621)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ public CompositePropertiesProvider(@NotNull List<PropertiesProvider> providers)

@Override
public @NotNull Map<String, String> getMap(final @NotNull String property) {
final Map<String, String> result = new ConcurrentHashMap<>();
for (final PropertiesProvider provider : providers) {
final Map<String, String> result = provider.getMap(property);
if (!result.isEmpty()) {
return result;
}
result.putAll(provider.getMap(property));
}
return new ConcurrentHashMap<>();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ class CompositePropertiesProviderTest {
whenever(second.getProperty("property")).thenReturn(null)
assertNull(provider.getProperty("property"))
}

@Test
fun `combines map results from multiple providers into single map`() {
whenever(first.getMap("tags")).thenReturn(mapOf("first_tag" to "val1"))
whenever(second.getMap("tags")).thenReturn(mapOf("second_tag" to "val2"))
assertEquals(mapOf("first_tag" to "val1", "second_tag" to "val2"), provider.getMap("tags"))
}

@Test
fun `when multiple providers return same map entries, the last one takes the precedence`() {
whenever(first.getMap("tags")).thenReturn(mapOf("first_tag" to "val1", "conflicting_tag" to "val3"))
whenever(second.getMap("tags")).thenReturn(mapOf("second_tag" to "val2", "conflicting_tag" to "val4"))
assertEquals(mapOf("first_tag" to "val1", "second_tag" to "val2", "conflicting_tag" to "val4"), provider.getMap("tags"))
}
}

0 comments on commit d9f2498

Please sign in to comment.