From 2ad0a4408309159d7b0bbcd2126150e439ce5b52 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 20 Oct 2016 14:17:12 -0400 Subject: [PATCH] INT-4145: Fix Mocking Issue JIRA: https://jira.spring.io/browse/INT-4145 Strange stubbing failure on spied template. Perhaps some JIT interaction since the method is used normally before stubbing. Change the spy to a mock for the last part of the test. Remove comment before the mock since it isn't relevant any more --- .../integration/amqp/outbound/AsyncAmqpGatewayTests.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java index 0850bce04f..04bf297083 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java @@ -95,7 +95,7 @@ public class AsyncAmqpGatewayTests { container.setQueueNames("asyncRQ1"); container.afterPropertiesSet(); container.start(); - AsyncRabbitTemplate asyncTemplate = spy(new AsyncRabbitTemplate(template, container)); + AsyncRabbitTemplate asyncTemplate = new AsyncRabbitTemplate(template, container); asyncTemplate.setEnableConfirms(true); asyncTemplate.setMandatory(true); asyncTemplate.start(); @@ -206,9 +206,7 @@ public class AsyncAmqpGatewayTests { ackChannel.receive(10000); ackChannel.purge(null); - // Simulate a nack - it's hard to get Rabbit to generate one - // We must have consumed all the real acks by now, though, to prevent partial stubbing errors - + asyncTemplate = mock(AsyncRabbitTemplate.class); RabbitMessageFuture future = asyncTemplate.new RabbitMessageFuture(null, null); willReturn(future).given(asyncTemplate).sendAndReceive(anyString(), anyString(), any(org.springframework.amqp.core.Message.class)); @@ -217,6 +215,7 @@ public class AsyncAmqpGatewayTests { SettableListenableFuture confirmFuture = new SettableListenableFuture(); confirmFuture.set(false); dfa.setPropertyValue("confirm", confirmFuture); + new DirectFieldAccessor(gateway).setPropertyValue("template", asyncTemplate); message = MessageBuilder.withPayload("buz").setErrorChannel(errorChannel).build(); gateway.handleMessage(message);