@SuppressWarnings("unchecked") @Test public void Memcachedからキャッシュを取得できた場合オブジェクトを返すこと() throws Exception { String cellName = "cellCacheTestCell"; Map<String, Object> cell = new HashMap<String, Object>(); Constructor<MemcachedClient> c = MemcachedClient.class.getDeclaredConstructor(); c.setAccessible(true); MemcachedClient mockMemcachedClient = spy(c.newInstance()); doReturn(cell).when(mockMemcachedClient).get(anyString(), any(Class.class)); PowerMockito.spy(CellCache.class); PowerMockito.when(CellCache.class, "getMcdClient").thenReturn(mockMemcachedClient); PowerMockito.spy(DcCoreConfig.class); PowerMockito.when(DcCoreConfig.class, "isCellCacheEnabled").thenReturn(true); Map<String, Object> cache = CellCache.get(cellName); assertEquals(cell, cache); }
public static Map<String, Object> get(String cellName) { if (!DcCoreConfig.isCellCacheEnabled()) { return null; } try { @SuppressWarnings("unchecked") Map<String, Object> cache = getMcdClient().get(cacheKey(cellName), Map.class); return cache; } catch (MemcachedClientException e) { log.info("Failed to get CellCache."); return null; } }
CellCache { public static Map<String, Object> get(String cellName) { if (!DcCoreConfig.isCellCacheEnabled()) { return null; } try { @SuppressWarnings("unchecked") Map<String, Object> cache = getMcdClient().get(cacheKey(cellName), Map.class); return cache; } catch (MemcachedClientException e) { log.info("Failed to get CellCache."); return null; } } }
CellCache { public static Map<String, Object> get(String cellName) { if (!DcCoreConfig.isCellCacheEnabled()) { return null; } try { @SuppressWarnings("unchecked") Map<String, Object> cache = getMcdClient().get(cacheKey(cellName), Map.class); return cache; } catch (MemcachedClientException e) { log.info("Failed to get CellCache."); return null; } } private  CellCache(); }
CellCache { public static Map<String, Object> get(String cellName) { if (!DcCoreConfig.isCellCacheEnabled()) { return null; } try { @SuppressWarnings("unchecked") Map<String, Object> cache = getMcdClient().get(cacheKey(cellName), Map.class); return cache; } catch (MemcachedClientException e) { log.info("Failed to get CellCache."); return null; } } private  CellCache(); static Map<String, Object> get(String cellName); static void cache(String cellName, Map<String, Object> cell); static void clear(String cellName); }
CellCache { public static Map<String, Object> get(String cellName) { if (!DcCoreConfig.isCellCacheEnabled()) { return null; } try { @SuppressWarnings("unchecked") Map<String, Object> cache = getMcdClient().get(cacheKey(cellName), Map.class); return cache; } catch (MemcachedClientException e) { log.info("Failed to get CellCache."); return null; } } private  CellCache(); static Map<String, Object> get(String cellName); static void cache(String cellName, Map<String, Object> cell); static void clear(String cellName);  }