SSMCache implements Cache { @Override public void clear() { if (!cache.isEnabled()) { LOGGER.warn("Cache {} is disabled. Cannot clear cache.", cache.getName()); return; } if (!allowClear) { LOGGER.error("Clearing cache '{}' is not allowed. To enable it set allowClear to true. " + "Make sure that caches don't overlap (one memcached instance isn't used by more than one cache) " + "otherwise clearing one cache will affect another.", getName()); throw new IllegalStateException("Cannot clear cache " + getName()); } try { LOGGER.info("Clear {}", cache.getName()); cache.flush(); } catch (TimeoutException | CacheException | RuntimeException e) { logOrThrow(e, "An error has ocurred for cache {}", getName(), e); } } SSMCache(final com.google.code.ssm.Cache cache, final int expiration, final boolean allowClear, final boolean registerAliases,
            final boolean muteExceptions);  SSMCache(final com.google.code.ssm.Cache cache, final int expiration, final boolean allowClear);  SSMCache(final com.google.code.ssm.Cache cache, final int expiration);  SSMCache(final SSMCache ssmCache, final int expiration); @Override String getName(); @Override Object getNativeCache(); @Override ValueWrapper get(final Object key); @Override @SuppressWarnings("unchecked") T get(final Object key, final Class<T> type); @Override @SuppressWarnings("unchecked") T get(final Object key, final Callable<T> valueLoader); @Override void put(final Object key, final Object value); @Override ValueWrapper putIfAbsent(final Object key, final Object value); @Override void evict(final Object key); @Override void clear();  }
@Test(expected = IllegalStateException.class) public void clearShouldThrowExceptionWhenNotAllowed() throws TimeoutException, CacheException { when(cache.isEnabled()).thenReturn(true); ssmCache.clear(); }
@Test public void clearShouldExecuteWhenCacheEnabled() throws TimeoutException, CacheException { ssmCache = new SSMCache(cache, expiration, true); when(cache.isEnabled()).thenReturn(true); ssmCache.clear(); verify(cache).flush(); }
@Test public void clearNotExecutedWhenCacheDisabled() throws TimeoutException, CacheException { ssmCache = new SSMCache(cache, expiration, true); when(cache.isEnabled()).thenReturn(false); ssmCache.clear(); verify(cache, never()).flush(); }