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