CacheFactory implements AddressChangeListener, FactoryBean<Cache>, InitializingBean, DisposableBean { protected Cache createCache() throws IOException { if (cache != null) { throw new IllegalStateException(String.format("This factory has already created memcached client for cache %s", cacheName)); } if (isCacheDisabled()) { LOGGER.warn("Cache {} is disabled", cacheName); cache = (Cache) Proxy.newProxyInstance(Cache.class.getClassLoader(), new Class[] { Cache.class }, new DisabledCacheInvocationHandler(cacheName, cacheAliases)); return cache; } if (configuration == null) { throw new RuntimeException(String.format("The MemcachedConnectionBean for cache %s must be defined!", cacheName)); } List<InetSocketAddress> addrs = addressProvider.getAddresses(); cache = new CacheImpl(cacheName, cacheAliases, createClient(addrs), defaultSerializationType, jsonTranscoder, javaTranscoder, customTranscoder, new CacheProperties(configuration.isUseNameAsKeyPrefix(), configuration.getKeyPrefixSeparator())); return cache; }  @Override void afterPropertiesSet(); @Override Cache getObject(); @Override Class<?> getObjectType(); @Override boolean isSingleton(); @Override void destroy(); @Override void changeAddresses(final List<InetSocketAddress> addresses);  }
@Test(expected = RuntimeException.class) public void testCreateClientException() throws IOException, NamingException { factory.createCache(); }