我需要编写一个测试来验证当私有方法_c抛出ioexception时,方法_b返回true。但是
public final class A{
public static Boolean Method_B(){
try{
//call a private method C which throws IOException
Method_C
}
catch(final IOException e) {
return Boolean.True
}
}
private static Method_C() throws IOException {
return something;
}
我尝试的是:
@Test
public void testSomeExceptionOccured() throws IOException {
A Amock = mock(A.class);
doThrow(IOException.class).when(Amock.Method_C(any(),any(),any(),any()));
Boolean x = A.Method_B(some_inputs);
Assert.assertEquals(Boolean.TRUE, x);
}
我遇到编译错误:1.无法模拟最终类2.方法c在
对如何纠正这一问题有何建议?
1条答案
按热度按时间dxxyhpgq1#
您需要在try-catch中使用finally