MessageUtils { public static Optional<Message> retry(Message message) { if (canRetry(message)) { return Optional.of(message(message.getCloudType(), message.getPayload(), message.getTtl() - 1)); } return Optional.empty(); }  static Optional<Message> retry(Message message); static boolean canRetry(Message message); static Message message(CloudType cloudType, Serializable payload, int ttl); static Message message(CloudType cloudType, Serializable payload); static Message message(Serializable payload); static String getRealQueueName(String queueName, CloudType cloudType);  }
@Test public void testRetry() { String payload = "anything"; assertThat(retry(message(MOCK, payload, 1)).isPresent(), is(false)); Message initialMessage = message(MOCK, payload, 42); Optional<Message> messageCandidate = retry(initialMessage); assertThat(messageCandidate.isPresent(), is(true)); Message retryMessage = messageCandidate.get(); assertThat(retryMessage.getId(), not(equalTo(initialMessage.getId()))); assertThat(retryMessage.getCloudType(), equalTo(initialMessage.getCloudType())); assertThat(retryMessage.getPayload(), equalTo(initialMessage.getPayload())); assertThat(retryMessage.getTtl(), equalTo(initialMessage.getTtl() - 1)); }