I have a class that after it does some stuff, sends a JMS message. I’d like to unit test the ‘stuff’, but not necessarily the sending of the message.
When I run my test, the ‘stuff’ green bars, but then fails when sending the message (it should, the app server is not running). What is the best way to do this, is it to mock the message queue, if so, how is that done.
I am using Spring, and ‘jmsTemplate’ is injected, along with ‘queue’.
The simplest answer I would use is to stub out the message sending functionality. For example, if you have this:
Then I would write a test that obscures the sendMessage behavior. For example:
If the amount of code that is stubbed out or obscured is substantial, I would not use an anonymous inner class but just a ‘normal’ inner class.