### Question:
ServientConfig { static Pair<String, ProtocolClientFactory> initializeClientFactory(Config config, String factoryName) throws ServientConfigException { try { Class<ProtocolClientFactory> factoryKlass = (Class<ProtocolClientFactory>) Class.forName(factoryName); Constructor<ProtocolClientFactory> constructor; ProtocolClientFactory factory; if (hasConstructor(factoryKlass, Config.class)) { constructor = factoryKlass.getConstructor(Config.class); factory = constructor.newInstance(config); } else { constructor = factoryKlass.getConstructor(); factory = constructor.newInstance(); } return new Pair<>(factory.getScheme(), factory); } catch (ClassCastException | ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new ServientConfigException(e); } } ServientConfig(List<ProtocolServer> servers,
                   Map<String, ProtocolClientFactory> clientFactories,
                   Map<String, Object> credentialStore);  ServientConfig(Config config); List<ProtocolServer> getServers(); Map<String, ProtocolClientFactory> getClientFactories(); Map<String, Object> getCredentialStore(); @Override String toString();  }### Answer:
@Test public void initializeClientFactory() throws ServientConfigException { Pair<String, ProtocolClientFactory> pair = ServientConfig.initializeClientFactory(config, MyProtocolClientFactory.class.getName()); assertThat(pair.first(), is("test")); assertThat(pair.second(), instanceOf(MyProtocolClientFactory.class)); }
@Test(expected = ServientConfigException.class) public void initializeClientFactoryWithoutImplementation() throws ServientConfigException { ServientConfig.initializeClientFactory(config, MyBadMissingImplementationProtocolClientFactory.class.getName()); }
@Test(expected = ServientConfigException.class) public void initializeClientFactoryMissingConstructor() throws ServientConfigException { ServientConfig.initializeClientFactory(config, MyBadMissingConstructorProtocolClientFactory.class.getName()); }