@Test public void namedConfigIsOnlyLoadedOnce() { DataStoreConfigurationSource sourceA = mock(DataStoreConfigurationSource.class); DataStoreConfigurationSource sourceB = mock(DataStoreConfigurationSource.class); DataStoreConfigurationSource sourceC = mock(DataStoreConfigurationSource.class); DataStoreConfigurationSource sourceD = mock(DataStoreConfigurationSource.class); DataStoreConfiguration configA = newDataStoreConfiguration("config", "sourceA"); DataStoreConfiguration configB = newDataStoreConfiguration("CONFIG", "sourceB"); DataStoreConfiguration configC = newDataStoreConfiguration("Config", "sourceC"); DataStoreConfiguration maven = newDataStoreConfiguration("maven", "sourceA"); DataStoreConfiguration docker = newDataStoreConfiguration("docker", "sourceB"); DataStoreConfiguration nuget = newDataStoreConfiguration("nuget", "sourceC"); when(sourceA.isEnabled()).thenReturn(true); when(sourceA.browseStoreNames()).thenReturn(ImmutableList.of("config", "maven")); when(sourceA.load("config")).thenReturn(configA); when(sourceA.load("maven")).thenReturn(maven); when(sourceB.isEnabled()).thenReturn(true); when(sourceB.browseStoreNames()).thenReturn(ImmutableList.of("docker", "CONFIG")); when(sourceB.load("CONFIG")).thenReturn(configB); when(sourceB.load("docker")).thenReturn(docker); when(sourceC.isEnabled()).thenReturn(false); when(sourceC.browseStoreNames()).thenReturn(ImmutableList.of("nuget", "Config")); when(sourceC.load("Config")).thenReturn(configC); when(sourceC.load("nuget")).thenReturn(nuget); when(sourceD.isEnabled()).thenReturn(true); when(sourceD.browseStoreNames()).thenReturn(ImmutableList.of("config", "pypi")); when(sourceD.load("config")).thenThrow(UncheckedIOException.class); when(sourceD.load("pypi")).thenThrow(UncheckedIOException.class); InOrder expected = inOrder(sourceA, sourceB, sourceC, sourceD); when(configurationSources.values()).thenReturn(ImmutableList.of(sourceC, sourceB, sourceD, sourceA)); assertThat(underTest.load(), contains(docker, configB, maven)); expected.verify(sourceB).load(matches("docker")); expected.verify(sourceB).load(matches("(?i)config")); expected.verify(sourceD).load(matches("pypi")); expected.verify(sourceA).load(matches("maven")); when(configurationSources.values()).thenReturn(ImmutableList.of(sourceD, sourceC, sourceB, sourceA)); assertThat(underTest.load(), contains(docker, maven)); expected.verify(sourceD).load(matches("(?i)config")); expected.verify(sourceD).load(matches("pypi")); expected.verify(sourceB).load(matches("docker")); expected.verify(sourceA).load(matches("maven")); when(configurationSources.values()).thenReturn(ImmutableList.of(sourceA, sourceB, sourceC, sourceD)); assertThat(underTest.load(), contains(configA, maven, docker)); expected.verify(sourceA).load(matches("(?i)config")); expected.verify(sourceA).load(matches("maven")); expected.verify(sourceB).load(matches("docker")); expected.verify(sourceD).load(matches("pypi")); expected.verifyNoMoreInteractions(); }
public Iterable<DataStoreConfiguration> load() { Set<String> configuredStores = new TreeSet<>(CASE_INSENSITIVE_ORDER); return configurationSources.values().stream() .filter(DataStoreConfigurationSource::isEnabled) .flatMap(source -> stream(source.browseStoreNames()) .filter(configuredStores::add) .map(configLoader(source))) .filter(Objects::nonNull) .collect(toImmutableList()); }
DataStoreConfigurationManager extends ComponentSupport { public Iterable<DataStoreConfiguration> load() { Set<String> configuredStores = new TreeSet<>(CASE_INSENSITIVE_ORDER); return configurationSources.values().stream() .filter(DataStoreConfigurationSource::isEnabled) .flatMap(source -> stream(source.browseStoreNames()) .filter(configuredStores::add) .map(configLoader(source))) .filter(Objects::nonNull) .collect(toImmutableList()); } }
DataStoreConfigurationManager extends ComponentSupport { public Iterable<DataStoreConfiguration> load() { Set<String> configuredStores = new TreeSet<>(CASE_INSENSITIVE_ORDER); return configurationSources.values().stream() .filter(DataStoreConfigurationSource::isEnabled) .flatMap(source -> stream(source.browseStoreNames()) .filter(configuredStores::add) .map(configLoader(source))) .filter(Objects::nonNull) .collect(toImmutableList()); } @Inject  DataStoreConfigurationManager(final Map<String, DataStoreConfigurationSource> configurationSources); }
DataStoreConfigurationManager extends ComponentSupport { public Iterable<DataStoreConfiguration> load() { Set<String> configuredStores = new TreeSet<>(CASE_INSENSITIVE_ORDER); return configurationSources.values().stream() .filter(DataStoreConfigurationSource::isEnabled) .flatMap(source -> stream(source.browseStoreNames()) .filter(configuredStores::add) .map(configLoader(source))) .filter(Objects::nonNull) .collect(toImmutableList()); } @Inject  DataStoreConfigurationManager(final Map<String, DataStoreConfigurationSource> configurationSources); Iterable<DataStoreConfiguration> load(); void save(final DataStoreConfiguration configuration); void delete(final DataStoreConfiguration configuration); }
DataStoreConfigurationManager extends ComponentSupport { public Iterable<DataStoreConfiguration> load() { Set<String> configuredStores = new TreeSet<>(CASE_INSENSITIVE_ORDER); return configurationSources.values().stream() .filter(DataStoreConfigurationSource::isEnabled) .flatMap(source -> stream(source.browseStoreNames()) .filter(configuredStores::add) .map(configLoader(source))) .filter(Objects::nonNull) .collect(toImmutableList()); } @Inject  DataStoreConfigurationManager(final Map<String, DataStoreConfigurationSource> configurationSources); Iterable<DataStoreConfiguration> load(); void save(final DataStoreConfiguration configuration); void delete(final DataStoreConfiguration configuration);  }