RedisCache extends AbstractCache<K, V> { @Override public void put(final K key, final V value) { try { client.set(serializer.serialize(key), serializer.serialize(value)); } catch (ConnectionException e) { throw new RedisCacheException(e); } catch (IOException e) { throw new RedisCacheException(e); } } RedisCache(final String name, final CacheLoader<K, V> cacheLoader,
      final EvictionListener<K, V> evictionListener,
      Serializer<Object> serializer, Client client); @Override void put(final K key, final V value); @Override void put(final K key, final V value, final TimeUnit timeUnit, final long duration); @Override @SuppressWarnings("unchecked") V get(final K key); @Override @SuppressWarnings("unchecked") V invalidate(final K key); @Override boolean contains(final K key); @Override void clear(); @Override long size(); @Override CacheStats stats();  }
@Test public void put() throws ConnectionException, IOException { int key = 3; int value = 5; cache.put(key, value); verify(client).set(serializer.serialize(key), serializer.serialize(value)); }
@Test public void putWithTimeout() throws ConnectionException, IOException { int key = 3; int value = 5; cache.put(key, value, TimeUnit.MILLISECONDS, 100); verify(client).set(serializer.serialize(key), serializer.serialize(value), 100); }
@Test(expected = RedisCacheException.class) public void putWithTimeoutThrowsIOException() throws ConnectionException, IOException { int key = 3; int value = 5; doThrow(new IOException("")).when(client).set(serializer.serialize(key), serializer.serialize(value), 100); cache.put(key, value, TimeUnit.MILLISECONDS, 100); }
@Test(expected = RedisCacheException.class) public void putConnectionException() throws ConnectionException, IOException { doThrow(new ConnectionException("")).when(client).set((byte[]) any(), (byte[]) any()); cache.put(3, 3); }
@Test(expected = RedisCacheException.class) public void putThrowIOException() throws ConnectionException, IOException { doThrow(new IOException("")).when(client).set((byte[]) any(), (byte[]) any()); cache.put(3, 3); }