【发布时间】:2021-02-19 01:03:38
【问题描述】:
我正在尝试为一个尝试从磁盘获取文件并将其流式传输的函数编写单元测试:
public InputStream downloadFile(String folderName, String fileName) throws FileNotFoundException {
File name = Paths.get("/tmp/portal", folderName, fileName).toFile();
return new FileInputStream(name);
}
我的尝试代码
@InjectMock MyService myService;
@TempDir
Path mockDirectory;
@Test
void downloadFile() throws IOException {
Path mockFile = mockDirectory.resolve("testFile");
Files.createFile(mockFile);
String folderName= mockFile.subpath(5, 6).toString();
String filename= mockFile.getFileName().toString();
InputStream inputStreamResult = myService.downloadFile(folderName, filename);
}
错误是
文件:testFile 不存在
【问题讨论】:
标签: java spring-boot unit-testing junit mockito