我如何模拟下一行:
Workbook templateWorkBook = null;
try {
templateWorkBook = new XSSFWorkbook(templateWithoutEvents);
} catch (IOException ex){
log.error("Error creating workbook from file");
}
我正在尝试这样的事情,但没有用。
try (
MockedConstruction<XSSFWorkbook> mocked = Mockito.mockConstructionWithAnswer(XSSFWorkbook.class, invocation -> null)
) {
doReturn("2021-09-30").when(stpConfigurationMock).getStartDate();
**when(new XSSFWorkbook()).thenThrow(IOException.class);**
Workbook workBook = fileService.generateReport(listItem, startDate, endDate);
}
运行测试时出现异常:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
有什么想法吗?谢谢,