I have some code that looks like the following:
class MyClass {
private JmsTemplate messageSender;
public void doStuff(Domain object domainObject){
... //other stuff
updateClient(domainObject);
}
...
private void updateClient(DomainObject domainObject){
final String payload = buildMessageForObject(domainObject);
messageSender.send(new MessageCreator() {
public Message createMessage(Session sn) throws JMSException {
return sn.createTextMessage(payload);
}
});
}
}
My JMS template is autowired by the Spring framework. The logic for buildMessageForObject is actually inlined, but if it weren't it would be private. What I'd like to do is to make assertions against the message payload string. It would be nice if the JMS API had something like jmsTemplate.sendTextMessage(String text) so that I could make verifications against the mocked jmsTemplate in my tests, but there seems to be too many layers of indirection between me and the message, and I can't see anything in the API for JMSTemplate or MessageCreator that obviously helps me restructure it to make it testable. I'm using JUnit and Mockito, but I don't know of any way that Mockito would allow me to specify the behaviour of the created MessageCreator.
Thanks in advance for any help.
Aucun commentaire:
Enregistrer un commentaire