Jayesh A Lalwani wrote:IMO, you should move the code that posts the HTTP request into it's own service. In your unit test you can mock the service.
That's actually a good idea (plus one for you)...sometimes, I get too bogged down in the problem that I miss the easy solutions. And further than just being a good idea, it makes my code testable, increases encapsulation, and making your recommended change isn't just 'writing code so that I can test'. Kudos.
However, that being said, I would still like any input apart from moving the method to a class and then mocking it. Although adequate and appropriate for this scenario, there are others coming up for me where this will not be a viable solution. That is, there will be instances in which I will want to expect a method invocation and not actually execute the code in said method.
From the research I've done on this, the name for what I'm describing is called 'spying' on a method. Doing what research I could on JMock and JUnit, it seems that this may be possible using some bevy of Invocation classes from JMock - I haven't been able to figure out how, though. It seems as though I should be able to basically write a dummy, or stub, method with the same method signature as the one being tested, and then somehow divert the method invocation to the stubbed method. Hope this helps anyone trying to help me.