public void testEvictionExceptionRecovery() throws CacheEvictionException { final CachePolicy cache = new MRU(1); final Object oldKey = "to-be-evicted"; final Object newKey = "insert-attempt"; { // null test cache.removeAll(); cache.put(oldKey, new Object()); assertNotNull(cache.get(oldKey)); cache.put(newKey, new Object()); assertNull(cache.get(oldKey)); assertNotNull(cache.get(newKey)); } { // stability test. cache.removeAll(); cache.addListener(new ThrowingListener()); cache.put(oldKey, new Object()); assertNotNull(cache.get(oldKey)); try { cache.put(newKey, new Object()); fail("Did not propagate expected exception."); } catch (CacheEvictionException cex) { assertNotNull("old object missing after eviction exception!", cache.get(oldKey)); assertNull( "new key -> object mapping added even when eviction exception!", cache.get(newKey)); } } }