I am using Mockit. I have a situation in which a method throws an exception, catches the exception and logs the exception (and without re-throwing).
Class Test {
public void abc() {
try {
xyz();
} catch (Exception e) {
LOGGER.error("Exception thrown {} ", e);
}
}
private void xyz() {
// Can throw exception
// which goes to the
// callee
}
}
Now, for some scenarios xyz() can throw exception and which is caught in abc(). It is this scenario I want to test. I can't use @Test(Expected=SomeException.class)
as the exception is being caught and logged. However, my test case should look if this exception thrown.
I did search online, however didn't find anything relevant.
Any pointer in how to approach would be helpful.
I referred to this SO question, which seems similar , but isn't what I am looking for.