spring-integration icon indicating copy to clipboard operation
spring-integration copied to clipboard

JmsChannelFactoryBean instanciating it's own jmsTemplate prevents mocking for test [INT-2679]

Open spring-operator opened this issue 13 years ago • 1 comments

Sylvain Mougenot opened INT-2679 and commented

Using jms:outbound-channel-adapter it's not possible to mock jmsTemplate (for test purposes) because JmsChannelFactoryBean instanciate it's own.

private final JmsTemplate jmsTemplate = new DynamicJmsTemplate();

It would be nice if we could inject the jmsTemplate.


Affects: 2.1.3

spring-operator avatar Jul 20 '12 07:07 spring-operator

Artem Bilan commented

Hello

Maybe this will be enough:

Field jmsTemplateField = ReflectionUtils.findField(AbstractJmsChannel.class, "jmsTemplate");
jmsTemplateField.setAccessible(true);
JmsTemplate jmsTemplate = Mockito.mock(JmsTemplate.class);
...
ReflectionUtils.setField(jmsTemplateField , jmsChannel, jmsTemplate );

?

spring-operator avatar Jul 20 '12 08:07 spring-operator