I had a confusion if I have to handle and test the exception for a class calling another class which handles the Exception.
Here is a basic explanation for my classes:
Class A -> Has a method and calls the method that throws exception. The exception is handled using try and catch
Class B -> calls the method from class A. It doesn't throw any exception now as the exception is handled in class A.
I wanted to know if I have to add throws and show that the exception is thrown in class B? Also, do I have to Unit test that the method called in class B throws exception? When I tried to do that, the test case failed.
Here is class A that handles the exception:
public String getFooData(Foo foo, String foo1, String foo2) {
String foodata = "";
try {
FooRequest request = foo.setFoo1(foo1).setFoo2(foo2).buildQueryMessage();
foodata = request.getFooData();
} catch (SystemException e) {
errorReporter.report(".SystemException", e);
}
}
Here is my class B:
public String getFoo(String foo2) {
RequestBuilder requestBuilder = Request.Provider(ProviderType.foo);
String foodata = instanceOfA.getFooData(foo, foo1, foo2);
return foodata;
}