EnumeratedIdentitySet implements Set<T> { @Override public Iterator<T> iterator() { return set.keySet().iterator(); } EnumeratedIdentitySet(Collection<? extends T> collection);  EnumeratedIdentitySet(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(Object o); @Override Iterator<T> iterator(); @Override Object[] toArray(); @Override T1[] toArray(T1[] a); @Override boolean add(T t); @Override boolean remove(Object o); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends T> collection); @Override boolean retainAll(Collection<?> collection); @Override boolean removeAll(Collection<?> collection); @Override void clear(); List<T> insertionOrderedList();  }
@Test public void iterator() { EnumeratedIdentitySet<Element> set = new EnumeratedIdentitySet<>(elements); IdentityHashMap<Element, Void> collectedElements = new IdentityHashMap<>(); int count = 0; for (Element element : set) { collectedElements.put(element, null); count++; } assertEquals(count, collectedElements.size()); assertEquals(elements.size(), collectedElements.size()); for (Element element : elements) { assertTrue(collectedElements.containsKey(element)); } }