次のクラスがあり、method2 と method3 をモックした method1 をテストしました。* method2 呼び出しが OK の場合 ==> OK * method2 が NotFoundException をスローし、method3 が OK を返す場合 ==> OK * method2 が NotFoundException をスローし、method3 が ServiceException をスローする場合 ==> ServiceException が実際にスローされる
method1 の機能だけをテストするために、メソッド method2 と method3 をモックしてもよろしいですか? また、method2 と method3 に個別のテストを追加したので、それらが完全に機能していることがわかります。
class ClassUnderTest {
public void method1() {
try {
method2();
} catch (NotFoundException e) {
method3()
}
}
public void method2() throws NotFoundException {
...
}
public void method3() throws ServiceException {
...
}
}