SmartList extends AbstractList<E> implements RandomAccess { @Override public boolean add(E e) { if (mySize == 0) { myElem = e; } else if (mySize == 1) { Object[] array = new Object[2]; array[0] = myElem; array[1] = e; myElem = array; } else { Object[] array = (Object[])myElem; int oldCapacity = array.length; if (mySize >= oldCapacity) { int newCapacity = oldCapacity * 3 / 2 + 1; int minCapacity = mySize + 1; if (newCapacity < minCapacity) { newCapacity = minCapacity; } Object[] oldArray = array; myElem = array = new Object[newCapacity]; System.arraycopy(oldArray, 0, array, 0, oldCapacity); } array[mySize] = e; } mySize++; modCount++; return true; } SmartList();  SmartList(E element);  SmartList(@NotNull Collection<? extends E> elements);  SmartList(@NotNull E... elements); @Override E get(int index); @Override boolean add(E e); @Override void add(int index, E e); @Override int size(); @Override void clear(); @Override E set(final int index, final E element); @Override E remove(final int index); @NotNull @Override Iterator<E> iterator(); void sort(Comparator<? super E> comparator); int getModificationCount(); @NotNull @Override T[] toArray(@NotNull T[] a); void trimToSize();  }
@Test public void testAddIndexedNegativeIndex() { SmartList<Integer> l = new SmartList<Integer>(); try { l.add(-1, 1); } catch (Exception e) { return; } fail("IndexOutOfBoundsException must be thrown, " + l); }
@Test public void testAddIndexedWrongIndex() { SmartList<Integer> l = new SmartList<Integer>(1); try { l.add(3, 1); } catch (Exception e) { return; } fail("IndexOutOfBoundsException must be thrown, " + l); }
@Test public void testAddIndexedEmptyWrongIndex() { SmartList<Integer> l = new SmartList<Integer>(); try { l.add(1, 1); } catch (Exception e) { return; } fail("IndexOutOfBoundsException must be thrown, " + l); }