It's usual to see logging functionality in the code:
public class A {
private static final Log LOG = LogFactory.getLog(A.class);
and usage:
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw e;
}
but I never saw even single unit test for such code.
Off course I do test throwing exception and exception type, but should I write test for checking logging information? I tend to think that logging is another part of system behavior, so it's quit logically to cover it in the tests.
Assuming that I should cover it, means that I should change my original code to inject mock log and check that "error" method was invoked with expected message. But what to do if my original class is service and it's instantiated by spring, should I inject some logger as well as other dependencies?