### Question:
QueueBuffer { public synchronized Message getFirstDeliverable() { submitMessageReads(); Node deliverableCandidate = firstDeliverableCandidate; if (deliverableCandidate != firstUndeliverable) { if (!deliverableCandidate.hasContent()) { return null; } firstDeliverableCandidate = deliverableCandidate.next; recordRemovingMessageForDelivery(); return deliverableCandidate.item; } else if (firstUndeliverable != null && firstUndeliverable.hasContent()) { Node newDeliverable = firstUndeliverable; firstDeliverableCandidate = firstUndeliverable.next; pushFirstUndeliverableCursor(); recordRemovingMessageForDelivery(); return newDeliverable.item; } else { return null; } } QueueBuffer(int inMemoryLimit, int indelibleMessageLimit, MessageReader messageReader); synchronized void add(Message message); synchronized void addAllBareMessages(Collection<Message> messages); synchronized void addBareMessage(Message message); synchronized boolean addIndelibleMessage(Message message); synchronized void remove(long messageId); synchronized void removeAll(Collection<DetachableMessage> messages); int size(); int getNumberOfInflightMessages(); int getNumberOfUndeliveredMessages(); synchronized Message getFirstDeliverable(); void markMessageFilled(Message message); void markMessageFillFailed(Message message); synchronized int clear(Consumer<Message> postDeleteAction);  }### Answer:
@Test public void testGetFirstDeliverable() { QueueBuffer queueBuffer = new QueueBuffer(10, 0, messageReader); for (int i = 0; i < 12; i++) { Message message = new Message(i + 1, mockMetadata); queueBuffer.add(message); } for (int i = 0; i < 12; i++) { Message message = queueBuffer.getFirstDeliverable(); Assert.assertNotNull(message.getMetadata(), "Messages returned from #getFirstDeliverable() should never " + "be empty"); queueBuffer.remove(message.getInternalId()); } Assert.assertEquals(queueBuffer.size(), 0, "Buffer size should be 0 after removing all messages"); }