MemcachedResponseStore extends ResponseStore { @Override public void put(String key, CachedResponse response) { checkNotNull(key); checkArgument(key.length() > 0, "key can not be empty"); checkNotNull(response); if (!_readOnly) { DateTime expires = response.getExpires().orNull(); if (expires != null) { _client.set(buildKey(key), (int) (expires.getMillis() / 1000), response, CachedResponseTranscoder.INSTANCE); } } } MemcachedResponseStore(MemcachedClient client, String keyPrefix, boolean readOnly); @Override Optional<CachedResponse> get(String key); @Override void put(String key, CachedResponse response); @Override void invalidate(String key);  }
@Test(dataProvider = "putData") public void put(String prefix, boolean readOnly, String key, String memcacheKey, int memcacheExpiration, CachedResponse value) { MemcachedClient client = mock(MemcachedClient.class); MemcachedResponseStore store = new MemcachedResponseStore(client, prefix, readOnly); store.put(key, value); if (!readOnly) { verify(client).set(eq(memcacheKey), eq(memcacheExpiration), same(value), any(Transcoder.class)); } verifyNoMoreInteractions(client); }
@Test public void put_with_no_expiration() { MemcachedClient client = mock(MemcachedClient.class); MemcachedResponseStore store = new MemcachedResponseStore(client, "", false); store.put("key", response(null)); verifyNoMoreInteractions(client); }