Is it possible to disable the execution of the logger during testing?
I have this class
public class UnitTestMe {
private final MockMe mockMe;
private final SomethingElse something;
private final Logger logger = LoggerFactory.getLogger(this.getClass().getClass());
public UnitTestMe(MockMe mockMe, SomethingElse something) {
this..
}
public toTest() {
logger.info("Executing toTest. MockMe a: {}, Foo: b: {}", mockMe.toString(), something.foo().bar());
mockMe.execute();
}
}
My Unit Test is failing with an NullPointerException because something.foo() is not a mocked object (i am using mockito with nicemock).
How can I test this class without removing the logger statement and without mocking irrelevant parts of the dependencies like something
?
Edit: something is in this case a Customer Object, that is not used in the toTest()
function but needed in other parts of this Class. I am using the Customer class in the logger statement to relate an action to an user.
Edit 2: Would it help to mock the logger object? I would assume that I will get an NullPointerException
again, because the methods of the `something´ object are executed, too.
try...catch (NullPointerException)
?NullPointerException
.