import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; public class MyArrayListTest { private MyArrayList list; @Before public void setUp() throws Exception { list = new MyArrayList(); } @Test public void testIsConstructorEmpty() { assertTrue(list.isEmpty()); } @Test public void testConstructorSize() { assertEquals(0,list.size()); } @Test public void testConstructorGet() { try { list.get(0); fail("expected exception"); } catch(IndexOutOfBoundsException e) { // expected behavior } } /* this also works... @Test(expected=IndexOutOfBoundsException) public void testConstructorGet() { list.get(0); } */ @Test public void testAddSize() { list.add(42); assertEquals(1,list.size()); } @Test public void testAddIsEmpty() { list.add(42); assertFalse(list.isEmpty()); } @Test public void testAddGet() { list.add(42); assertEquals(42,list.get(0)); } @Test public void testRemove() { list.add(7); assertEquals(7,list.remove(0)); } @Test public void testRemoveIsEmpty() { list.add(7); list.remove(0); assertTrue(list.isEmpty()); } }