CacheRepositoryImpl implements CacheRepository { public void evict(Object key) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Removing object from cache [" + cacheName + "] for key [" + key + "]"); } getCache().evict(key); }  EhCacheCacheManager getEhCacheCacheManager(); void setEhCacheCacheManager(EhCacheCacheManager ehCacheCacheManager); String getCacheName(); void setCacheName(String cacheName); Object get(Object key); void put(Object key, Object value); void evict(Object key); Object getNativeCache(); long getMemoryUsage(); long getMemoryStoreSize();  }
@Test public void evict() { CacheRepository cacheRepository = new CacheRepositoryImpl(); ((CacheRepositoryImpl) cacheRepository).setCacheName(cacheName); ((CacheRepositoryImpl) cacheRepository).setEhCacheCacheManager(ehCacheCacheManager); String keyRemove = "keyRemove1"; String valRemove = "valRemove1"; cacheRepository.put(keyRemove, valRemove); long size = cacheRepository.getMemoryStoreSize(); Assert.assertTrue("Same value should be retrieved ", valRemove.equals(cacheRepository.get(keyRemove))); System.out.println("1 ->" + cacheRepository.getMemoryStoreSize()); cacheRepository.evict(keyRemove); System.out.println("2 ->" + cacheRepository.getMemoryStoreSize()); Assert.assertEquals("size should reduce by 1", size - 1, cacheRepository.getMemoryStoreSize()); cacheRepository.evict(keyRemove); Assert.assertEquals("Non existing Key removal, size should be the same as last time", size - 1, cacheRepository.getMemoryStoreSize()); System.out.println("3 ->" + cacheRepository.getMemoryStoreSize()); }