ExpiringMap implements Map<K, V> { @Override public V remove(Object key) { ExpiringValue<V> expValue = map.remove(key); if (expValue != null) { return expValue.value; } return null; } ExpiringMap(int expirationPeriod, int checkerPeriod, ScheduledExecutorService executor);  ExpiringMap(ScheduledExecutorService executor); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override boolean containsValue(Object value); @Override V get(Object key); @Override V put(K key, V value); @Override V remove(Object key); @Override void putAll(Map<? extends K, ? extends V> m); @Override void clear(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<java.util.Map.Entry<K, V>> entrySet();  }
@Test public void remove() { Map<String, String> map = new ExpiringMap<>(executor); map.put("key1", "value1"); map.put("key2", "value2"); String val = map.remove("key2"); assertEquals("value2", val); assertEquals(1, map.size()); assertTrue(map.containsKey("key1")); }