FallbackConfigurationSource implements ConfigurationSource { @Override public void init() { boolean atLeastOneSuccess = false; for (ConfigurationSource source : sources) { try { source.init(); atLeastOneSuccess = true; } catch (IllegalStateException | SourceCommunicationException e) { } } if (!atLeastOneSuccess) { throw new IllegalStateException("Unable to initialize any of the underlying sources"); } } FallbackConfigurationSource(ConfigurationSource... sources); @Override Properties getConfiguration(Environment environment); @Override void init(); @Override String toString();  }
@Test void initInitializesAllSources() { for (ConfigurationSource underlyingSource : underlyingSources) { verify(underlyingSource, atLeastOnce()).init(); } }
@Test void initThrowsWhenAllSourcesThrow() { makeAllSourcesThrow(new IllegalStateException()); assertThatThrownBy(() -> fallbackConfigurationSource.init()).isExactlyInstanceOf(IllegalStateException.class); }
@Test void initIgnoresIllegalStateExceptionsIfAtLeastOneSourceSucceeds() { makeAllSourcesThrow(new IllegalStateException()); doNothing().when(underlyingSources[LAST_SOURCE_INDEX]).init(); fallbackConfigurationSource.init(); }
@Test void initIgnoresSourceCommunicationExceptionsIfAtLeastOneSourceSucceeds() { makeAllSourcesThrow(new SourceCommunicationException("", null)); doNothing().when(underlyingSources[LAST_SOURCE_INDEX]).init(); fallbackConfigurationSource.init(); }