For unit testing, one problem I've run into is overriding the returns from
static class methods.
For instance, PutJMS contains this code:
try {
> wrappedProducer = JmsFactory.createMessageProducer(context, true);
> logger.info("Connected to JMS server {}",
> new Object[]{conte
You could move the one static call into an instance method of PutJMS, and use
Mockito.spy() to get a partial mock of the processor, then use when() to
override the instance method in the test. Not sure if that's how it's done in
other places but it's worked for me in the past.
Regards,
Matt
Se
If you get it into a protected instance method, you can also make an inner
class in your test, something like TestablePutJMS extends PutJMS, and
overrides that method to return a mock or whatever you want. That is a
common pattern in a lot of the processor tests.
On Fri, Dec 18, 2015 at 3:44 PM, M
Wrapping createMessageProducer() in an instance method is a good
suggestion, but it seems overkill just to enable testing. Prompted by
Oleg's suggestion, I got around instance variable visibility with
Reflection, which is nice because it doesn't require "private" be changed
to "protected" in the c
Personally I am with Joe on this one
Exposing visibility on the method just for testing is very dangerous as it
breaks encapsulation. There are different expectations and consideration on
things that are made private, protected and public. Yes, all of that is
meaningless when one uses reflectio
Definitely a topic ripe for debate :) In my view there’s a whole spectrum, with
one side being the case Oleg describes, where the existing encapsulation is not
compromised solely for the sake of testing. On the far side is pure
design-by-contract. For example, the case could be made that the JMS
You could use PowerMock to either call private static methods directly
or to mock them out.
https://github.com/jayway/powermock/wiki/MockStatic
https://github.com/jayway/powermock/wiki/MockPrivate
https://github.com/jayway/powermock/wiki/BypassEncapsulation#invoking-a-private-method
On Fri, Dec