テストプログラム

TDUList4Test


package tdu;
import static org.junit.Assert.*;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.junit.Test;
public class TDUList4Test {
	@Test
	public void testListIterator() {
		ListIterator<String> listIterator = (new TDUList4()).listIterator(0);
		Class<?> superClass= new TDUListIterator3(null, 0).getClass();
		assertEquals(superClass, listIterator.getClass().getSuperclass());
	}
	@Test
	public void test0() {
		TDUList4 list = new TDUList4();
		Iterator<String> iterator = list.iterator();
		assertFalse(iterator.hasNext());
	}
	@Test(expected=NoSuchElementException.class)
	public void test01() {
		TDUList4 list = new TDUList4();
		Iterator<String> iterator = list.iterator();
		assertFalse(iterator.hasNext());
		iterator.next();
	}
	@Test
	public void test3() {
		TDUList4 list = new TDUList4();
		Node<String> n0 = new Node<String>();
		Node<String> n3 = new Node<String>("abc");
		Node<String> n2 = new Node<String>(null);
		Node<String> n1 = new Node<String>("efg");
		n1.next=n0;
		n2.next=n1;
		n3.next=n2;
		list.node = n3;
		Iterator<String> iterator = list.iterator();
		assertTrue(iterator.hasNext());
		assertEquals("abc",iterator.next());
		assertTrue(iterator.hasNext());
		assertEquals(null,iterator.next());
		assertTrue(iterator.hasNext());
		assertEquals("efg",iterator.next());
		assertFalse(iterator.hasNext());
	}
	@Test(expected=NoSuchElementException.class)
	public void testAdd(){
		TDUList4 list = new TDUList4();
		list.add("hij");
		list.add(null);
		list.add("nop");
		Iterator<String> iterator = list.iterator();
		assertTrue(iterator.hasNext());
		assertEquals("hij",iterator.next());
		assertTrue(iterator.hasNext());
		assertEquals(null,iterator.next());
		assertTrue(iterator.hasNext());
		assertEquals("nop",iterator.next());
		assertFalse(iterator.hasNext());
                iterator.next();
	}
}