### Question:
ArrayList extends List<E> { public void ensureCapacity(int minimumCapacity) { int required = minimumCapacity - array.length; if (required > 0) { if (firstIndex > 0) { growAtFront(required); } else { growAtEnd(required); } } } 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:
@Test public void testEnsureCapacity() { Object testObject = new Object(); int capacity = 20; ArrayList<Object> al = new ArrayList<Object>(capacity); int i; for (i = 0; i < capacity / 2; i++) { al.add(i, new Object()); } al.add(i, testObject); int location = al.indexOf(testObject); al.ensureCapacity(capacity); assertTrue("EnsureCapacity moved objects around in array1.", location == al.indexOf(testObject)); al.remove(0); al.ensureCapacity(capacity); assertTrue("EnsureCapacity moved objects around in array2.", --location == al.indexOf(testObject)); al.ensureCapacity(capacity + 2); assertTrue("EnsureCapacity did not change location.", location == al.indexOf(testObject)); }