public void testIterator() { Iterator iter = (Iterator) makeFullIterator(); for ( int i = 0; i < testArray.length; i++ ) { Object testValue = testArray[i]; Object iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); } assertTrue("Iterator should now be empty", ! iter.hasNext() ); try { Object testValue = iter.next(); } catch (Exception e) { assertTrue("NoSuchElementException must be thrown", e.getClass().equals((new NoSuchElementException()).getClass())); } }
public void testRemove() { Iterator iter = (Iterator) makeFullIterator(); try { iter.remove(); fail("Calling remove before the first call to next() should throw an exception"); } catch (IllegalStateException e) { } for ( int i = 0; i < testArray.length; i++ ) { Object testValue = testArray[i]; Object iterValue = iter.next(); assertEquals( "Iteration value is correct", testValue, iterValue ); if (! iterValue.equals("Four")) { iter.remove(); } } assertTrue("List is empty",list1.size() == 0); assertTrue("List is empty",list2.size() == 1); assertTrue("List is empty",list3.size() == 0); }
public void testFirstIteratorIsEmptyBug() { List empty = new ArrayList(); List notEmpty = new ArrayList(); notEmpty.add("A"); notEmpty.add("B"); notEmpty.add("C"); IteratorChain chain = new IteratorChain(); chain.addIterator(empty.iterator()); chain.addIterator(notEmpty.iterator()); assertTrue("should have next",chain.hasNext()); assertEquals("A",chain.next()); assertTrue("should have next",chain.hasNext()); assertEquals("B",chain.next()); assertTrue("should have next",chain.hasNext()); assertEquals("C",chain.next()); assertTrue("should not have next",!chain.hasNext()); }