@Test
public void poll_messagesReceived() throws Exception {

    when(messageDispatcher.getEstimatedCapacity(any()))
            .thenReturn(4)
            .thenReturn(2)
            .thenReturn(0);
    List<Message> messages = Lists.newArrayList(mock(Message.class), mock(Message.class));
    when(sqsProxy.receiveMessages(anyInt())).thenReturn(messages);
    poller.poll(SQSPoller.TIMEOUT_BUFFER_IN_MILLIS * 2);
    Instant expectedCutoff = NOW.plusMillis(SQSPoller.TIMEOUT_BUFFER_IN_MILLIS);
    InOrder inOrder = inOrder(messageDispatcher, sqsProxy);
    inOrder.verify(messageDispatcher).reset();
    inOrder.verify(messageDispatcher).getEstimatedCapacity(expectedCutoff);
    inOrder.verify(sqsProxy).receiveMessages(4);
    inOrder.verify(messageDispatcher).dispatch(messages);
    inOrder.verify(messageDispatcher).getEstimatedCapacity(expectedCutoff);
    inOrder.verify(sqsProxy).receiveMessages(2);
    inOrder.verify(messageDispatcher).dispatch(messages);
    inOrder.verify(messageDispatcher).getEstimatedCapacity(expectedCutoff);
    verifyNoMoreInteractions(sqsProxy, messageDispatcher);
}