AbstractCache implements IDataCache<T> { @Override public boolean dataExists(long id) { boolean result = false; lock.readLock().lock(); try { if (dataIsInCache(id)) { result = true; } else { result = cachedStorage.dataExists(id); } } finally { lock.readLock().unlock(); } return result; } AbstractCache(S entries, IDataStorage<T> cachedStorage, long maxCacheSize,
      Predicate<T> cachingRule); @Override long getMaxCacheSize(); @Override boolean setMaxCacheSize(long maxCacheSize); @Override long getCurrentCacheSize(); @Override long getFreeSpace(); @Override boolean hasStorageFor(long size); @Override void cacheData(T data); @Override void uncacheData(T data); @Override boolean dataIsCachable(T data); @Override boolean dataIsInCache(long id); @Override void clearCache(); @Override boolean dataExists(long id); @Override T loadData(long id); @Override boolean saveData(T data); @Override boolean dataIsStorable(T data); @Override boolean deleteData(T data);  }
@Test public void testDataExists() { AbstractCacheWrapper uut = new AbstractCacheWrapper(entries, null, 20000, predicate -> true); assertFalse(uut.dataExists(c0.getId())); uut.cacheData(c0); uut.cacheData(c2); assertTrue(uut.dataExists(c0.getId())); assertFalse(uut.dataExists(c1.getId())); assertTrue(uut.dataExists(c2.getId())); assertFalse(uut.dataExists(c3.getId())); entries.clear(); uut = new AbstractCacheWrapper(entries, storageAll, 20000, predicate -> true); assertTrue(uut.dataExists(c0.getId())); assertTrue(uut.dataExists(c1.getId())); assertTrue(uut.dataExists(c2.getId())); assertTrue(uut.dataExists(c3.getId())); }