RedisCache extends AbstractCache<K, V> { @Override @SuppressWarnings("unchecked") public V invalidate(final K key) { try { byte[] serializedKey = serializer.serialize(key); byte[] serializedValue = client.expire(serializedKey); V value = (V) serializer.deserialize(serializedValue); evictionListener.onEviction(key, value); stats.incrementEvictionCount(); return value; } catch (ConnectionException|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 invalidate() throws ConnectionException, IOException { int key = 3; int value = 5; doReturn(serializer.serialize(value)).when(client).expire(serializer.serialize(key)); int actualValue = cache.invalidate(key); assertEquals(value, actualValue); verify(evictionListener).onEviction(key, value); }
@Test(expected = RedisCacheException.class) public void invalidateConnectionException() throws ConnectionException, IOException { int key = 3; doThrow(new ConnectionException("")).when(client).expire(serializer.serialize(key)); cache.invalidate(key); }
@Test(expected = RedisCacheException.class) public void invalidateThrowIOException() throws ConnectionException, IOException { int key = 3; doThrow(new IOException("")).when(client).expire(serializer.serialize(key)); cache.invalidate(key); }