CacheSimple implements Cache<K,V> { @Override public long size() { return currentSize ; } CacheSimple(int size); @Override void clear(); @Override boolean containsKey(K key); @Override V getIfPresent(K key); @Override V getOrFill(K key, Callable<V> callable); @Override void put(K key, V thing); @Override void remove(K key); @Override long size(); @Override Iterator<K> keys(); @Override boolean isEmpty(); @Override void setDropHandler(BiConsumer<K,V> dropHandler);  }
@Test public void testFixedSize() { final int maxSize = 5; final int submittedEntries = 10; final Cache<Integer, Object> testCache = new CacheSimple<>(maxSize); rangeClosed(1, submittedEntries) .boxed() .collect(toMap(k -> k, v -> 1)) .forEach(testCache::put); assertEquals("Test cache failed to maintain fixed size!", maxSize, testCache.size()); }