I have a method which looks like this:
Most of the code I'll want to mock is happening within the new MessageCreator's createMessage() method. It's not clear how I could mock that, since the MessageCreator is an object which gets created anew each time the method runs. I know I can mock the JmsTemplate, Destination, Session, and AdminMessageXmlConverter and set these into the corresponding properties of my class and the JmsTemplate, but how I would go about mocking the MessageCreator is a mystery. Or maybe I'm taking the wrong approach and using mocks is the wrong way to test this kind of code?
public void registerHost(final String hostManifestLocation)
// send an AdminMessage for registering a host
jmsTemplate.send(this.destination, new MessageCreator()
public Message createMessage(final Session session)
// build an AdminMessage for registering a host
AdminMessage adminMessage = new AdminMessage();
// return an XML representation of the AdminMessage
catch (Exception ex)
throw new RuntimeException("Unable to register the host specified by the manifest file \'"
+ hostManifestLocation + "\'", ex);
If anyone can give me some ideas I'll certainly appreciate it. Thanks in advance!