ExtendedIteratorCounterThread implements Runnable { @Override public void run() { if (null != listener) { long count = 0; while (itr != null && itr.hasNext()) { listener.setIntermediaryCount(++count); itr.next(); } listener.setCount(count); listener.setCountComplete(); } } @SuppressWarnings("unchecked")  ExtendedIteratorCounterThread(Iterator itr, ExtendedCountListener listener); @Override void run();  }
@Test public void testRun() throws Exception { Assert.assertEquals(0, count); Thread p = new Thread(counter); p.start(); p.join(); Assert.assertEquals(NUM_ELEMENTS, count); Assert.assertEquals(interCount, count); Assert.assertTrue(countComplete); }