### Question:
FairQueue implements BlockingQueue<E> { @Override public boolean retainAll (Collection<?> c) { boolean modified = false; List<Object> removeKeys = new ArrayList<Object> (); for (Object key : keys) { boolean res = storage.get (key).retainAll (c); modified = modified || res; if (storage.get (key).isEmpty ()) { storage.remove (key); removeKeys.add (key); } } keys.removeAll(removeKeys); int ct = 0; for (Object key : keys) { ct += storage.get (key).size (); } count.set (ct); return modified; } FairQueue(); @Override int size(); @Override int remainingCapacity(); @Override void put(E e); @Override boolean offer(E e); @Override boolean offer(E e, long timeout, TimeUnit unit); @Override E take(); @Override E peek(); @Override E poll(); @Override E poll(long timeout, TimeUnit unit); @Override int drainTo(Collection<? super E> c); @Override int drainTo(Collection<? super E> c, int maxElements); @Override void clear(); @Override boolean contains(Object o); @Override Object[] toArray(); @Override T[] toArray(T[] a); @Override Iterator<E> iterator(); @Override E remove(); @Override E element(); @Override boolean isEmpty(); @Override boolean containsAll(Collection<?> c); @Override boolean addAll(Collection<? extends E> c); @Override boolean removeAll(Collection<?> c); @Override boolean retainAll(Collection<?> c); @Override boolean add(E e); @Override boolean remove(Object o);  }### Answer:
@Test public void testRetainAll() { ArrayList<FairQueueTestString> list = new ArrayList<>(); list.add(new FairQueueTestString("key1", "item1")); list.add(new FairQueueTestString("key1", "item2")); list.add(new FairQueueTestString("key1", "item7")); list.add(new FairQueueTestString("key2", "item4")); list.add(new FairQueueTestString("key2", "item5")); queue.offer(new FairQueueTestString("key1", "item1")); queue.offer(new FairQueueTestString("key1", "item2")); queue.offer(new FairQueueTestString("key1", "item3")); queue.offer(new FairQueueTestString("key2", "item4")); queue.offer(new FairQueueTestString("key2", "item5")); Assert.assertEquals(queue.size(), 5); Assert.assertEquals(queue.retainAll(list), true); Assert.assertEquals(queue.size(), 4); ArrayList<FairQueueTestString> list2 = new ArrayList<>(); list2.add(new FairQueueTestString("key1", "item1")); list2.add(new FairQueueTestString("key1", "item2")); list2.add(new FairQueueTestString("key1", "item3")); list2.add(new FairQueueTestString("key2", "item4")); list2.add(new FairQueueTestString("key2", "item5")); Assert.assertEquals(queue.retainAll(list2), false); }