IteratorCounterThread implements Runnable { @Override public void run() { long count = 0; while (itr != null && itr.hasNext()) { count++; itr.next(); } if (listener != null) { listener.setCount(count); } } @SuppressWarnings("unchecked")  IteratorCounterThread(Iterator itr, CountListener 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); }