### Question:
ArrayList extends List<E> { @Override public E remove(int location) { E result; if (location < 0 || location >= itemCount) { throw new ProgrammerError("Index out of bounds; index: {}, size: {}", location, itemCount); } if (location == 0) { result = array[firstIndex]; array[firstIndex++] = SystemUtils.<E>defaultValue(); } else if (location == itemCount - 1) { int lastIndex = firstIndex + itemCount - 1; result = array[lastIndex]; array[lastIndex] = SystemUtils.<E>defaultValue(); } else { int elementIndex = firstIndex + location; result = array[elementIndex]; if (location < itemCount / 2) { SystemUtils.arraycopy(array, firstIndex, array, firstIndex + 1, location); array[firstIndex++] = SystemUtils.<E>defaultValue(); } else { SystemUtils.arraycopy(array, elementIndex + 1, array, elementIndex, itemCount - location - 1); array[firstIndex + itemCount - 1] = SystemUtils.<E>defaultValue(); } } itemCount--; if (itemCount == 0) { firstIndex = 0; } modCount++; return result; } ArrayList();  ArrayList(int capacity);  ArrayList(Collection<E> collection);  ArrayList(E... args); @Override void add(int location, E object); @Override boolean add(E object); @Override boolean addAll(int location, Collection<? extends E> collection); @Override boolean addAll(Collection<? extends E> collection); @Override void clear(); @Override boolean contains(E object); void ensureCapacity(int minimumCapacity); @Override E get(int location); @Override int indexOf(E object); @Override boolean isEmpty(); @Override int lastIndexOf(E object); @Override Iterator<E> iterator(); @Override E remove(int location); @Override boolean remove(E object); @Override E set(int location, E object); @Override int size(); @Override Object[] toArray(); @Override void toArray(E[] contents); void sortInPlace(Comparator<E> comparator); void trimToSize();  }### Answer:
@SuppressWarnings("unchecked") @Test public void testRemove() { alist.remove(10); assertEquals("Failed to remove element", -1, alist.indexOf(objArray[10])); try { alist.remove(999); fail("Failed to throw exception when index out of range"); } catch (ProgrammerError e) { assertTrue(e.getMessage().startsWith("Index out of bounds")); } ArrayList<Object> myList = new ArrayList<Object>(alist); alist.add(25, null); alist.add(50, null); alist.remove(50); alist.remove(25); assertTrue("Removing nulls did not work", alist.equalTo(myList)); List<String> list = new ArrayList<String>("a", "b", "c", "d", "e", "f", "g"); assertTrue("Removed wrong element 1", list.remove(0) == "a"); assertTrue("Removed wrong element 2", list.remove(4) == "f"); assertTrue("Removed wrong element 3", list.equalTo(new ArrayList<String>("b", "c", "d", "e", "g"))); List<Object> l = new ArrayList<Object>(0); l.add(new Object()); l.add(new Object()); l.remove(0); l.remove(0); try { l.remove(-1); fail("-1 should cause exception"); } catch (ProgrammerError e) { assertTrue(e.getMessage().startsWith("Index out of bounds")); } try { l.remove(0); fail("0 should case exception"); } catch (ProgrammerError e) { assertTrue(e.getMessage().startsWith("Index out of bounds")); } }