As a follow up I will show how I'm currently testing the code using EasyMock:
Code:
@Test
public void testRegisterHost()
{
// mock objects used within the method under test
Destination mockDestination = EasyMock.createMock(Destination.class);
JmsTemplate mockJmsTemplate = EasyMock.createMock(JmsTemplate.class);
mockJmsTemplate.send(EasyMock.eq(mockDestination), EasyMock.isA(MessageCreator.class));
EasyMock.replay(mockJmsTemplate);
// instantiate the class, set its properties, and execute the method under test
AdminCLI adminCLI = new AdminCLI();
adminCLI.setDestination(mockDestination);
adminCLI.setJmsTemplate(mockJmsTemplate);
adminCLI.registerHost(null);
// verify that the mocks behaved as expected
EasyMock.verify(mockJmsTemplate);
}
However this only verifies that the JmsTemplate.send() method is being called as expected, whereas it's more interesting for me to determine that the expected code within the MessageCreator's createMessage() method is executing as well, and this is what I can't figure out how to test using mocks. I hope this makes my question more clear.
--James