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 Sent from my iPhone > On Dec 18, 2015, at 3:20 PM, Joe Skora <[email protected]> wrote: > > 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[]{context.getProperty(URL).getValue()}); >> } catch (final JMSException e) { >> logger.error("Failed to connect to JMS Server due to {}", new >> Object[]{e}); >> session.transfer(flowFiles, REL_FAILURE); >> context.yield(); >> return; >> } > > where JmsFactory.createmessageProducer call being defined as > > public static WrappedMessageProducer createMessageProducer(... > > which presents a problem since it can't be easily overridden for a unit > test. Exercising the > > How you handle this problem? > > Regards, > Joe
