ScopedMap implements ScopeSubscriber, Map<K, V> { public Set<Map.Entry<K, V>> entrySet() { final Set<Map.Entry<K, Stack<ScopedMapItem<V>>>> entries = map.entrySet(); final Set<Map.Entry<K, V>> set = new java.util.HashSet<Map.Entry<K, V>>(); for (Map.Entry<K, Stack<ScopedMapItem<V>>> entry : entries) { final K key = entry.getKey(); final ScopedMapEntry<K, V> current = new ScopedMapEntry<K, V>(key, this); set.add(current); } return set; } ScopedMap(final ScopeObserver scopeObserver); void close(); void enterScope(final Scope previous, final Scope next); void exitScope(final Scope previous, final Scope next); int size(); boolean isEmpty(); boolean containsKey(final Object key); boolean containsValue(final Object value); V get(final Object key); V put(final K key, final V value); V remove(final Object key); void putAll(final Map<? extends K, ? extends V> t); void clear(); Set<K> keySet(); Collection<V> values(); Set<Map.Entry<K, V>> entrySet(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testEntrySet() { final ScopedMap<String, String> map = new ScopedMap<String, String>(observer); map.enterScope(Scope.SESSION, Scope.DOCUMENT); Assert.assertNull(map.put("key1", "value1")); Assert.assertNull(map.put("key2", "value2")); final Set<Map.Entry<String, String>> entries = map.entrySet(); Assert.assertFalse(entries.isEmpty()); for (Map.Entry<String, String> entry : entries) { final String key = entry.getKey(); Assert.assertTrue(key.equals("key1") || key.equals("key2")); final String value = entry.getValue(); Assert.assertTrue(value.equals("value1") || value.equals("value2")); } final Iterator<Map.Entry<String, String>> iterator = entries.iterator(); final Map.Entry<String, String> entry1 = iterator.next(); final String key1 = entry1.getKey(); final String value1 = entry1.getValue(); final String value3 = "value3"; Assert.assertEquals(value1, map.get(key1)); Assert.assertEquals(value1, entry1.setValue(value3)); Assert.assertEquals(value3, entry1.getValue()); Assert.assertEquals(value3, map.get(key1)); final String value4 = "value4"; Assert.assertEquals(value3, entry1.setValue(value4)); Assert.assertEquals(value4, entry1.getValue()); Assert.assertEquals(value4, map.get(key1)); }