I am unit testing a class which is as below :
class ClassUnderTest {
public SomeOtherClass var;
public String methodUnderTest(){
try {
//call to some other method that throws CustomException
String localvariable = var.someOtherMethod() //throws CustomException
// generic operations on localvariable which can throw Exception
} catch (CustomException e) {
s.o.p(e);
} catch (Exception e) {
s.o.p(e);
}
}
}
The problem arises when I have to test the methodUnderTest for catching Exception.class. I can not mock SomeOtherClass to throw Exception as Exception is a checked exception and someOtherMethod throws only CustomException. How can I make a test case for this scenario ?