### Question:
FairQueue implements BlockingQueue<E> { @Override public E poll () { final AtomicInteger count = this.count; if (count.get () == 0) { return null; } E x = null; int c = -1; final ReentrantLock lock = this.lock; lock.lock (); try { if (count.get () > 0) { x = getNext (true); c = count.getAndDecrement (); if (c > 1) { notEmpty.signal (); } } } finally { lock.unlock (); } return x; } 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 testPoll() { Assert.assertEquals(queue.size(), 0); FairQueueTestString s = queue.poll(); Assert.assertNull(s); 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); s = queue.poll(); Assert.assertNotNull(s); Assert.assertEquals(s.getItem(), "item1"); Assert.assertEquals(queue.size(), 4); s = queue.poll(); Assert.assertNotNull(s); Assert.assertEquals(s.getItem(), "item4"); Assert.assertEquals(queue.size(), 3); }