@Test public void testRetry() throws Exception { ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class); final AtomicInteger count = new AtomicInteger(); willAnswer(invocation -> { count.incrementAndGet(); throw new AuthenticationFailureException("foo"); }).given(mockConnectionFactory).newConnection(any(ExecutorService.class), anyString()); SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory); connectionFactory.setExecutor(mock(ExecutorService.class)); RabbitTemplate template = new RabbitTemplate(connectionFactory); template.setRetryTemplate(new RetryTemplate()); try { template.convertAndSend("foo", "bar", "baz"); } catch (AmqpAuthenticationException e) { assertThat(e.getMessage(), containsString("foo")); } assertEquals(3, count.get()); }