RedisCache extends AbstractCache<K, V> { @Override public long size() { try { return client.dbsize(); } 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 size() throws ConnectionException, IOException { int size = 3; doReturn(size).when(client).dbsize(); long actualSize = cache.size(); assertEquals(size, actualSize); }
@Test(expected = RedisCacheException.class) public void sizeThrowConnectionException() throws ConnectionException, IOException { doThrow(new ConnectionException("")).when(client).dbsize(); cache.size(); }
@Test(expected = RedisCacheException.class) public void sizeThrowIOException() throws ConnectionException, IOException { doThrow(new IOException("")).when(client).dbsize(); cache.size(); }