FileDocCategorySizeDatePackage
ArrayIteratorTest.javaAPI DocExample713Sat Mar 03 15:18:26 GMT 2001None

ArrayIteratorTest.java

import junit.framework.*;
public class ArrayIteratorTest extends TestCase {

	String[] TESTDATA = { "one", "two", "three" };

	ArrayIterator it = new ArrayIterator(TESTDATA);

	/** JUnit test classes require this constructor */
	public ArrayIteratorTest(String name) {
		super(name);
	}

	/** Simple tryout */
	public void testGetting() {
		int i = 0;
		while (it.hasNext()) {
			assertEquals(TESTDATA[i++], it.next());
		}

		// XXX read up on writing JUnit tests that should throw exceptions
		try {
			it.next();		// EXPECT RUNTIME ERROR
			System.err.println("ERROR - DID NOT GET EXPECTED EXCEPTION");
		} catch (IndexOutOfBoundsException e) {
			System.err.println("Got expected exception -- OK!");
		}
	}
}