ExpiringMap extends LinkedHashMap<K, V> { void removeOldEntries() { Iterator<Map.Entry<K, V>> iterator = entrySet().iterator(); while (iterator.hasNext()) { Map.Entry<K, V> entry = iterator.next(); if (entry.getValue().isExpired()) { iterator.remove(); } else { return; } } }    }
@Test public void testRemove_IfEmpty() throws Exception { ExpiringMap<String, Expirable> map = new ExpiringMap<String, Expirable>(); map.removeOldEntries(); }