MergeConfigurationSource implements ConfigurationSource { @Override public Properties getConfiguration(Environment environment) { Properties properties = new Properties(); for (ConfigurationSource source : sources) { Properties sourceProperties = source.getConfiguration(environment); properties.putAll(sourceProperties); } return properties; } MergeConfigurationSource(ConfigurationSource... sources); @Override Properties getConfiguration(Environment environment); @Override void init(); @Override String toString();  }
@Test void getConfigurationThrowsWhenOneOfSourcesThrowsOnMissingEnvironment() { when(underlyingSources[1].getConfiguration(ArgumentMatchers.any())).thenThrow(new MissingEnvironmentException("")); assertThatThrownBy(() -> mergeConfigurationSource.getConfiguration(new ImmutableEnvironment("test"))).isExactlyInstanceOf(MissingEnvironmentException.class); }
@Test void getConfigurationThrowsWhenOneOfSourcesThrows() { when(underlyingSources[3].getConfiguration(ArgumentMatchers.any())).thenThrow(new IllegalStateException()); assertThatThrownBy(() -> mergeConfigurationSource.getConfiguration(new ImmutableEnvironment("test"))).isExactlyInstanceOf(IllegalStateException.class); }
@Test void getConfigurationMergesConfigurations() { Environment environment = new ImmutableEnvironment("test"); sourcesWithProps(environment, "prop1", "value1", "prop2", "value2"); assertThat(mergeConfigurationSource.getConfiguration(environment)).containsOnly(MapEntry.entry("prop1", "value1"), MapEntry.entry("prop2", "value2")); }
@Test void getConfigurationMergesConfigurationsWithCollidingKeys() { Environment environment = new ImmutableEnvironment("test"); sourcesWithProps(environment, "prop", "value1", "prop", "value2"); assertThat(mergeConfigurationSource.getConfiguration(environment)).containsOnly(MapEntry.entry("prop", "value2")); }