### Question:
ListIndex implements Index<Key,Value> { public long size() { return size.get(); } ListIndex();  ListIndex(PageFile pageFile, long headPageId); @SuppressWarnings("rawtypes")  ListIndex(PageFile pageFile, Page page); @Override synchronized void load(Transaction tx); @Override synchronized void unload(Transaction tx); @Override synchronized boolean containsKey(Transaction tx, Key key); @Override @SuppressWarnings({ "rawtypes", "unchecked" }) synchronized Value get(Transaction tx, Key key); @Override @SuppressWarnings({ "rawtypes" }) synchronized Value put(Transaction tx, Key key, Value value); synchronized Value add(Transaction tx, Key key, Value value); synchronized Value addFirst(Transaction tx, Key key, Value value); @Override @SuppressWarnings("rawtypes") synchronized Value remove(Transaction tx, Key key); void onRemove(Entry<Key, Value> removed); @Override boolean isTransient(); @Override synchronized void clear(Transaction tx); synchronized Iterator<ListNode<Key, Value>> listNodeIterator(Transaction tx); synchronized boolean isEmpty(final Transaction tx); @Override synchronized Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx); synchronized Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx, long initialPosition); synchronized Map.Entry<Key,Value> getFirst(Transaction tx); synchronized Map.Entry<Key,Value> getLast(Transaction tx); ListNode<Key,Value> createNode(Transaction tx); void storeNode(Transaction tx, ListNode<Key,Value> node, boolean overflow); PageFile getPageFile(); void setPageFile(PageFile pageFile); long getHeadPageId(); void setHeadPageId(long headPageId); Marshaller<Key> getKeyMarshaller(); @Override void setKeyMarshaller(Marshaller<Key> keyMarshaller); Marshaller<Value> getValueMarshaller(); @Override void setValueMarshaller(Marshaller<Value> valueMarshaller); void setTailPageId(long tailPageId); long getTailPageId(); long size(); final static long NOT_SET; }### Answer:
@Test(timeout=60000) public void testSize() throws Exception { createPageFileAndIndex(100); ListIndex<String, Long> listIndex = ((ListIndex<String, Long>) this.index); this.index.load(tx); tx.commit(); int count = 30; tx = pf.tx(); doInsert(count); tx.commit(); assertEquals("correct size", count, listIndex.size()); tx = pf.tx(); Iterator<Map.Entry<String, Long>> iterator = index.iterator(tx); while (iterator.hasNext()) { iterator.next(); iterator.remove(); assertEquals("correct size", --count, listIndex.size()); } tx.commit(); count = 30; tx = pf.tx(); doInsert(count); tx.commit(); assertEquals("correct size", count, listIndex.size()); tx = pf.tx(); listIndex.clear(tx); assertEquals("correct size", 0, listIndex.size()); tx.commit(); }