### Question:
SimpleArrayList extends AbstractList<E> implements List<E> { @Override public void add(int index, E element) { if (index < 0 || index > size()) { throw new IndexOutOfBoundsException("Invalid index"); } if (arr.length == size) { Object[] temparr = new Object[size * 2]; for (int i = 0; i < size; i++) { counter += 2; temparr[i] = arr[i]; } arr = temparr; } for (int i = size; i > index; i--) { counter += 2; arr[i] = arr[i - 1]; } counter++; arr[index] = element; size++; }  @Override int size(); @SuppressWarnings("unchecked") @Override E get(int index); @Override E set(int index, E element); @Override void add(int index, E element); @Override E remove(int index); long getCounter();  }### Answer:
@Test public void testIndexAdd_WithoutEnlarge() { int[] numbers = new int[]{1, 4, 6, 7}; for (int i = numbers.length - 1; i >= 0; i--) { list.add(0, numbers[i]); } assertListValues(numbers); }
@Test(expected = IndexOutOfBoundsException.class) public void testAddOnNegativIndex_ExpectException() { list.add(-1, 2); fail("Exception was expected"); }
@Test(expected = IndexOutOfBoundsException.class) public void testAddOnHugeTooLargeIndex_ExpectException() { list.add(0, 1); list.add(44444, 2); fail("Exception was expected"); }
@Test(expected = IndexOutOfBoundsException.class) public void testAddOnSmallTooLargeIndex_ExpectException() { list.add(0, 1); list.add(2, 2); fail("Exception was expected"); }
@Test public void testAddWithEnlarge() { int[] numbers = new int[1000]; for (int i = 0; i < numbers.length; i++) { numbers[i] = i; list.add(i, i); } assertListValues(numbers); }
@Test public void testAddWithEnlargeReverse() { int[] numbers = new int[1000]; for (int i = numbers.length - 1; i >= 0; i--) { numbers[i] = i; list.add(0, i); } assertListValues(numbers); }
@Test public void testAddAnywhere() { int[] numbers = {10, 21, 11, 22, 12, 23, 13, 24, 14, 25, 15, 26, 16, 27, 17, 28, 0, 29, 1, 30, 2, 31, 3, 32, 4, 33, 5, 34, 6, 35, 7, 36}; for (int i = 0; i < 8; i++) list.add(i); for (int i = 0; i < 8; i++) list.add(i, 10 + i); for (int i = 16; i > 0; i--) list.add(i, 20 + i); assertListValues(numbers); }
@Test public void addNullValue() { list.add(null); }