### Question:
ReQueueConsumer { @RabbitListener(queues = "${rabbitmq.auto-config.re-queue-config.queue.name}") public void onMessage(ReQueueMessage reQueueMessage) { int count = 0; do { Message message = rabbitTemplate.receive(reQueueMessage.getDeadLetterQueue(), timeout); if (message == null) { break; } Map<String, Object> headers = message.getMessageProperties().getHeaders(); if (reQueuePolicy.canReQueue(message)) { String queueName = (String) headers.get("x-original-queue"); rabbitTemplate.send(queueName, message); } count++; } while (reQueueMessage.getMessageCount() < 0 || reQueueMessage.getMessageCount() > count); }  @RabbitListener(queues = "${rabbitmq.auto-config.re-queue-config.queue.name}") void onMessage(ReQueueMessage reQueueMessage);  }### Answer:
@Test public void reQueueMessageUntilTheMessageCount() { when(rabbitTemplate.receive(anyString(), anyLong())).thenReturn(message); reQueueConsumer.onMessage(reQueueMessage); verify(rabbitTemplate, times(2)).send(anyString(), any(Message.class)); }
@Test public void shouldNotReQueueIfTheMessageIsNull() { when(rabbitTemplate.receive(anyString(), anyLong())).thenReturn(null); reQueueConsumer.onMessage(reQueueMessage); verify(rabbitTemplate, times(0)).send(anyString(), any(Message.class)); }