I’m writing tests using Junit4 and mockito and wondering if there is a possibility to check if specific exception was thrown and handled inside tested method.
What I mean is – I have for example following simple method:
public int someMethodAsInt(String key, int defaultValue) {
try {
return Integer.parseInt(someMethod(key, String.valueOf(defaultValue)));
} catch (NumberFormatException e) {
return defaultValue;
}
}
I know that i can make test like that:
int result = myService.someMethodAsInt("key", 123);
assertEquals(123, result);
I just wonder if there is a way to check that the exception was thrown and caught inside the tested method. I can use only Junit4 or Mockito, I know that there are some other extensions, but we don’t use them in project.