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?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) throws JMSException { try { // build an AdminMessage for registering a host AdminMessage adminMessage = new AdminMessage(); adminMessage.setActionType(AdminActionType.REGISTER_HOST); adminMessage.setPhysicalHost(buildPhysicalHost(hostManifestLocation)); // return an XML representation of the AdminMessage return session.createTextMessage(adminMessageXmlConverter.objectToXml(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!
--James


Reply With Quote
