### Question:
PreAllocatedArray implements Iterable<T> { public T get(final int index) { return internal.get(index); } PreAllocatedArray(final int capacity); T set(final int index, final T element); T get(final int index); @Override Iterator<T> iterator(); final int length; }### Answer:
@Test public void testGetIndexHigh() { PreAllocatedArray<String> strings = new PreAllocatedArray<>(3); strings.get(2); assertThrows(IndexOutOfBoundsException.class, () -> strings.get(3)); }
@Test public void testGetIndexNegative() { PreAllocatedArray<String> strings = new PreAllocatedArray<>(3); strings.get(0); assertThrows(IndexOutOfBoundsException.class, () -> strings.get(-3)); }