I am trying to do a full junit testing of my application and I am stuck when It comes to test the logger messages.
try {
fillParameters(args);
} catch (ArgumentException e) {
logger.error(e.getMessage(), e);
return;
}
Here is the code which triggers the exception :
if (args.length > 3) {
throw new ArgumentException("Wrong use of the command -> too many args");
}
One test :
@Test
public void testFillParametersWithTooManyArguments() {
String[] args = { "...", "...", "...", "..." };
Throwable e = null;
try {
testInstance.fillParameters(args);
} catch (Throwable ex) {
e = ex;
}
assertTrue(e instanceof ArgumentException); //this test is working as expected
}
when I take a look at the code coverage, the logger.error(e.getMessage(), e); part is not covered, how am I supposed to cover it? I assume I must mock the logger?