### Question:
UpstreamDatabaseStrategiesLoader implements Iterable<UpstreamDatabaseSelectionStrategy> { @Override public Iterator<UpstreamDatabaseSelectionStrategy> iterator() { Iterable<UpstreamDatabaseSelectionStrategy> allImplementationsOnClasspath = Service.load( UpstreamDatabaseSelectionStrategy.class ); LinkedHashSet<UpstreamDatabaseSelectionStrategy> candidates = new LinkedHashSet<>(); for ( String key : config.get( CausalClusteringSettings.upstream_selection_strategy ) ) { for ( UpstreamDatabaseSelectionStrategy candidate : allImplementationsOnClasspath ) { if ( candidate.getKeys().iterator().next().equals( key ) ) { candidate.inject( topologyService, config, logProvider, myself ); candidates.add( candidate ); } } } log( candidates ); return candidates.iterator(); } UpstreamDatabaseStrategiesLoader( TopologyService topologyService, Config config, MemberId myself, LogProvider logProvider ); @Override Iterator<UpstreamDatabaseSelectionStrategy> iterator();  }### Answer:
@Test public void shouldReturnConfiguredClassesOnly() { Config config = Config.defaults( upstream_selection_strategy, "dummy" ); UpstreamDatabaseStrategiesLoader strategies = new UpstreamDatabaseStrategiesLoader( mock( TopologyService.class ), config, myself, NullLogProvider.getInstance() ); Set<UpstreamDatabaseSelectionStrategy> upstreamDatabaseSelectionStrategies = asSet( strategies.iterator() ); assertEquals( 1, upstreamDatabaseSelectionStrategies.size() ); assertEquals( UpstreamDatabaseStrategySelectorTest.DummyUpstreamDatabaseSelectionStrategy.class, upstreamDatabaseSelectionStrategies.stream().map( UpstreamDatabaseSelectionStrategy::getClass ).findFirst().get() ); }
@Test public void shouldReturnTheFirstStrategyThatWorksFromThoseConfigured() { Config config = Config.defaults( upstream_selection_strategy, "yet-another-dummy,dummy,another-dummy" ); UpstreamDatabaseStrategiesLoader strategies = new UpstreamDatabaseStrategiesLoader( mock( TopologyService.class ), config, myself, NullLogProvider.getInstance() ); assertEquals( UpstreamDatabaseStrategySelectorTest.YetAnotherDummyUpstreamDatabaseSelectionStrategy.class, strategies.iterator().next().getClass() ); }