AmazonSQSIterator implements Iterator<List<Message>>, Closeable { @Override public List<Message> next() { LOGGER.debug( "Requesting {} messages from SQS (wait time={}, visibility timeout={})", MAX_NUMBER_OF_MESSAGES, WAIT_TIME_SECS, VISIBILITY_TIMEOUT_SECS); receiveRequests.inc(); final ReceiveMessageResult result = sqs.receiveMessage(request); final int numMessages = result.getMessages().size(); LOGGER.debug("Received {} messages from SQS", numMessages); messageCounts.update(numMessages); return result.getMessages(); } AmazonSQSIterator(final AmazonSQS sqs, final String queueUrl); @Override boolean hasNext(); @Override List<Message> next(); boolean deleteMessage(@Nullable final Message message); @Override void close();  }
@Test public void testNext() throws Exception { final ReceiveMessageResult expected = new ReceiveMessageResult(); when(mockSQS.receiveMessage(any(ReceiveMessageRequest.class))).thenReturn(expected); final List<Message> actual = iterator.next(); assertThat(actual).isEqualTo(expected.getMessages()); }