public StatementLocksFactory select() { StatementLocksFactory statementLocksFactory; String serviceName = StatementLocksFactory.class.getSimpleName(); List<StatementLocksFactory> factories = serviceLoadFactories(); if ( factories.isEmpty() ) { statementLocksFactory = new SimpleStatementLocksFactory(); log.info( "No services implementing " + serviceName + " found. " + "Using " + SimpleStatementLocksFactory.class.getSimpleName() ); } else if ( factories.size() == 1 ) { statementLocksFactory = factories.get( 0 ); log.info( "Found single implementation of " + serviceName + ". Namely " + statementLocksFactory.getClass().getSimpleName() ); } else { throw new IllegalStateException( "Found more than one implementation of " + serviceName + ": " + factories ); } statementLocksFactory.initialize( locks, config ); return statementLocksFactory; }
@Test public void loadSingleAvailableFactory() { Locks locks = mock( Locks.class ); StatementLocksFactory factory = mock( StatementLocksFactory.class ); StatementLocksFactorySelector loader = newLoader( locks, factory ); StatementLocksFactory loadedFactory = loader.select(); assertSame( factory, loadedFactory ); verify( factory ).initialize( same( locks ), any( Config.class ) ); }
public StatementLocksFactory select() { StatementLocksFactory statementLocksFactory; String serviceName = StatementLocksFactory.class.getSimpleName(); List<StatementLocksFactory> factories = serviceLoadFactories(); if ( factories.isEmpty() ) { statementLocksFactory = new SimpleStatementLocksFactory(); log.info( "No services implementing " + serviceName + " found. " + "Using " + SimpleStatementLocksFactory.class.getSimpleName() ); } else if ( factories.size() == 1 ) { statementLocksFactory = factories.get( 0 ); log.info( "Found single implementation of " + serviceName + ". Namely " + statementLocksFactory.getClass().getSimpleName() ); } else { throw new IllegalStateException( "Found more than one implementation of " + serviceName + ": " + factories ); } statementLocksFactory.initialize( locks, config ); return statementLocksFactory; }