FlatFileBufferLinkedList implements NodeStateEntryList { @Override public Iterator<NodeStateEntry> iterator() { return NodeIterator.iteratorFor(head); } FlatFileBufferLinkedList();  FlatFileBufferLinkedList(long memLimit); void add(@NotNull NodeStateEntry item); NodeStateEntry remove(); @Override Iterator<NodeStateEntry> iterator(); @Override int size(); @Override boolean isEmpty(); @Override long estimatedMemoryUsage(); @Override void close();  }
@Test public void iterator() { assertEquals("empty list must be 0-sized", 0, Iterators.size(list.iterator())); list.add(testNode("/")); assertEquals("single entry list must be 1-sized", 1, Iterators.size(list.iterator())); assertEquals("single entry list must be 1-sized on separate iterators", 1, Iterators.size(list.iterator())); list.add(testNode("/a")); assertEquals("2 entries in list must be 2-sized", 2, Iterators.size(list.iterator())); assertEquals("2 entries in list must be 2-sized on separate iterators", 2, Iterators.size(list.iterator())); Iterator<NodeStateEntry> iter2 = list.iterator(); Iterator<NodeStateEntry> iter1 = list.iterator(); assertEquals("/", iter2.next().toString()); assertEquals("2 entries in list must be 1-sized after consuming an item", 1, Iterators.size(iter2)); assertEquals("2 entries in list must be 2-sized even if some other iterator consumed an item", 2, Iterators.size(iter1)); list.add(testNode("/b")); iter1 = list.iterator(); iter2 = list.iterator(); assertEquals("/", iter1.next().toString()); assertEquals("/", iter2.next().toString()); assertEquals("/a", iter2.next().toString()); assertEquals("/", list.remove().toString()); assertEquals("/a", list.remove().toString()); try { iter1.next(); fail("Iterator state once removed from list can't be traversed"); } catch (IllegalStateException ise) { } assertEquals(testNode("/b"), iter2.next()); assertEquals("2 entries in list must be 1-sized after removal of an iterm", 1, Iterators.size(list.iterator())); }