### Question:
LimitedFifoObservableList extends ModifiableObservableListBase<T> { @Override public boolean addAll(Collection<? extends T> elements) { Collection<? extends T> toBeAdded = elements; if (toBeAdded.size() > maxSize) { toBeAdded = new ArrayList<>(toBeAdded).subList(elements.size() - maxSize, elements.size()); } boolean modified = false; int deletions = Math.max(0, toBeAdded.size() - (maxSize - size())); int addFrom = size() - deletions; beginChange(); nextRemove(0, list.subList(0, deletions)); for (T element : toBeAdded) { if (size() < maxSize) { int biasedIndex = getRelativeIndex(size()); list.add(biasedIndex, element); if (biasedIndex <= zeroElementPointer) { incrementZeroElementPointer(); } } else { list.set(zeroElementPointer, element); incrementZeroElementPointer(); } modCount++; modified = true; } nextAdd(addFrom, size()); endChange(); return modified; } LimitedFifoObservableList(int maxSize); int getMaxSize(); @Override T get(int index); @Override int size(); @Override boolean add(T element); @Override boolean addAll(Collection<? extends T> elements); @Override void clear(); @Override void add(int index, T element); @Override boolean addAll(int index, Collection<? extends T> elements); @Override boolean remove(Object element); @Override T remove(int index); @Override void remove(int from, int to); @Override boolean removeAll(Collection<?> elements); @Override boolean removeAll(@SuppressWarnings("unchecked") T... elements); @Override boolean removeIf(Predicate<? super T> filter); @Override void replaceAll(UnaryOperator<T> operator); @Override boolean retainAll(Collection<?> elements); @Override boolean retainAll(@SuppressWarnings("unchecked") T... elements); @Override T set(int index, T element); @Override boolean setAll(Collection<? extends T> col); @Override boolean setAll(@SuppressWarnings("unchecked") T... elements); @Override void sort(Comparator<? super T> comparator);  }### Answer:
@Test public void testContainsAll() { final List<String> list = getListWithMaxSize(3); list.addAll(TEST_COLLECTION_3); assertTrue(list.containsAll(TEST_COLLECTION_3)); }
@Test(expected = IndexOutOfBoundsException.class) public void testSubListNegativeIndex() { final List<String> list = getListWithMaxSize(3); list.addAll(TEST_COLLECTION_3); assertThat(list.subList(-1, 3), is(Arrays.asList(TEST_ELEMENT_3, TEST_ELEMENT_1))); }
@Test(expected = IndexOutOfBoundsException.class) public void testSubListIndexGreaterSize() { final List<String> list = getListWithMaxSize(4); list.addAll(TEST_COLLECTION_3); assertThat(list.subList(1, 4), is(Arrays.asList(TEST_ELEMENT_3, TEST_ELEMENT_1))); }
@Test public void testAddAll() { final List<String> list = getListWithMaxSize(3); list.addAll(TEST_COLLECTION_1); assertThat(list.size(), is(1)); assertThat(list.get(0), is(TEST_ELEMENT_1)); list.addAll(TEST_COLLECTION_2); assertThat(list.size(), is(3)); assertThat(list.get(0), is(TEST_ELEMENT_1)); assertThat(list.get(1), is(TEST_ELEMENT_1)); assertThat(list.get(2), is(TEST_ELEMENT_2)); list.addAll(TEST_COLLECTION_3); assertThat(list.size(), is(3)); assertThat(list.get(0), is(TEST_ELEMENT_1)); assertThat(list.get(1), is(TEST_ELEMENT_2)); assertThat(list.get(2), is(TEST_ELEMENT_3)); }
@Test(expected = UnsupportedOperationException.class) public void testAddAllAtIndex() { final List<String> list = getListWithMaxSize(2); list.addAll(0, TEST_COLLECTION_2); }