I have a couple of classes: StateProcessor and State.
I want to write a test for the method StateProcessor.process(State).
The logic of this method is pretty simple, but it contains a lot of logging messages.
logger.info(state.getSourse().toString());
if (state.getTarget() == Target.A) {
logger.info(state.getCreationTime());
service.doSmth(state);
} else {
logger.info(state.getTagret().getName());
service.doOtherStff(state);
}
I don’t want to pass the real State instance to the process method because this class is really complicated and it takes a lot of lines of code to build it. So, I want to pass mock object created with Mockito. According to the main logic, I need to mock only getTarget() method. But the execution will fail with NPE at state.getTagret().getName() and at state.getSourse().toString(). But I don’t like the idea of mocking all of these methods! They used only for logging. Also I don’t want to fix my tests every time when I add some logging messages.
Logging is really useful there, so I don’t want to remove it at all. But mocking the methods only for logging looks strange.
How I can solve this issue?
Consider Mocking DEEP. This will result in each method call returning a mock instead of
nulland prevent the NPEs.