IntList { public int set(int i, int val) { checkIndex(i); int old = buf[i]; buf[i] = val; return old; } IntList(int capacity);  IntList(); int[] toArray(); int size(); int get(int i); int set(int i, int val); void ensureCapacity(int capacity); IntList add(int i);  }
@Test public void testSet() { IntList intList = new IntList(0); intList.add(1); intList.set(0, 2); assertEquals(2, intList.get(0)); assertEqualArray(intList.toArray(), 2); }
@Test public void testSet_throwsForNegativeIndex() { IntList intList = new IntList(); try { intList.set(-1, 0); fail(); } catch (ArrayIndexOutOfBoundsException e) {} }
@Test public void testSet_throwsForIndexOutOfBounds() { IntList intList = new IntList(); try { intList.set(0, 0); fail(); } catch (ArrayIndexOutOfBoundsException e) {} }