SSMCache implements Cache { @Override public ValueWrapper get(final Object key) { if (!cache.isEnabled()) { LOGGER.warn("Cache {} is disabled. Cannot get {} from cache", cache.getName(), key); return null; } Object value = getValue(key); if (value == null) { LOGGER.info("Cache miss. Get by key {} from cache {}", key, cache.getName()); return null; } LOGGER.info("Cache hit. Get by key {} from cache {} value '{}'", new Object[] { key, cache.getName(), value }); return value instanceof PertinentNegativeNull ? new SimpleValueWrapper(null) : new SimpleValueWrapper(value); } 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 public void getShouldExecuteWhenCacheEnabled() throws TimeoutException, CacheException { when(cache.isEnabled()).thenReturn(true); String key = "someCacheKey"; ssmCache.get(key); verify(cache).get(key, null); }
@Test public void getNotExecutedWhenCacheDisabled() throws TimeoutException, CacheException { String key = "someCacheKey"; when(cache.isEnabled()).thenReturn(false); final Object result = ssmCache.get(key); verify(cache, never()).get(key, null); assertNull(result); }
@Test public void getWithValueLoaderNotExecutedWhenCacheDisabled() throws TimeoutException, CacheException { String key = "someCacheKey"; when(cache.isEnabled()).thenReturn(false); final Object expectedResult = new Object(); final Object result = ssmCache.get(key, new Callable<Object>() { @Override public Object call() throws Exception { return expectedResult; } }); verify(cache, never()).get(anyString(), any(SerializationType.class)); verify(cache, never()).set(anyString(), anyInt(), any(), any(SerializationType.class)); verify(cache, never()).setSilently(anyString(), anyInt(), any(), any(SerializationType.class)); assertEquals(expectedResult, result); }
@Test(expected = SSMCache.ValueRetrievalException.class) public void getWithValueLoaderShouldWrapException() throws TimeoutException, CacheException { String key = "someCacheKey"; when(cache.isEnabled()).thenReturn(false); ssmCache.get(key, new Callable<Object>() { @Override public Object call() throws Exception { throw new Exception("some exception"); } }); }