【发布时间】:2012-09-26 14:37:07
【问题描述】:
我必须使用 Mockito 抛出一个 IOException 方法,该方法正在读取如下所示的输入流。有什么办法吗?
public void someMethod(){
try{
BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
firstLine = in.readLine();
}catch(IOException ioException){
//Do something
}
我试着模仿
BufferedReader buffReader = Mockito.mock(BufferedReader.class);
Mockito.doThrow(new IOException()).when(buffReader).readLine();
但没有成功:(
【问题讨论】:
标签: java unit-testing mocking mockito