void () { int N = 10; fillWithInts(N); gc(); Iterator<?> iterator = myWeakList.iterator(); for (int i = 0; i < N; i++) { assertTrue(iterator.hasNext()); //noinspection ConstantConditions assertTrue(iterator.hasNext()); int element = (Integer)iterator.next(); assertEquals(i, element); } assertFalse(iterator.hasNext()); int elementCount = 0; for (Object element : myWeakList) { assertEquals(elementCount, element); elementCount++; } assertEquals(N, elementCount); }