AmazonSQSIterator implements Iterator<List<Message>>, Closeable { public boolean deleteMessage(@Nullable final Message message) { if (message == null) { return false; } try { LOGGER.debug("Deleting message from SQS: {}", message.getMessageId()); deleteRequests.inc(); sqs.deleteMessage(queueUrl, message.getReceiptHandle()); return true; } catch (Exception e) { LOGGER.error("Failed to delete message: " + message.getMessageId(), e); } return false; } 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 testDeleteMessage() throws Exception { final Message message = new Message(); message.setReceiptHandle("myReceipt"); final boolean actual = iterator.deleteMessage(message); verify(mockSQS).deleteMessage(QUEUE_URL, "myReceipt"); assertThat(actual).isTrue(); }
@Test public void testDeleteMessageException() throws Exception { doThrow(new AmazonServiceException("error")) .when(mockSQS) .deleteMessage(QUEUE_URL, "myReceipt"); final Message message = new Message(); message.setReceiptHandle("myReceipt"); final boolean actual = iterator.deleteMessage(message); verify(mockSQS).deleteMessage(QUEUE_URL, "myReceipt"); assertThat(actual).isFalse(); }
@Test public void testDeleteMessageNull() throws Exception { final boolean actual = iterator.deleteMessage(null); assertThat(actual).isFalse(); }