假设我有一个方法:
public void copyAndMoveFiles() throws IOException {
Path source = Paths.get(path1);
Path target = Paths.get(path2);
if (Files.notExists(target) && target != null) {
Files.createDirectories(Paths.get(target.toString()));
}
for (String fileInDirectory: Files.readAllLines(source.resolve(fileToRead))) {
Files.copy(source.resolve(fileInDirectory), target.resolve(fileInDirectory), StandardCopyOption.REPLACE_EXISTING);
}
}
我该如何对此进行单元测试?我尝试过使用Mockito,但它没有返回任何结果或我可以断言的内容。我了解了JimFs,但出于某些原因,我无法理解它。
/tmp/src/file1.txt
和一个空目录/tmp/dest
,使用此方法复制文件,并断言/tmp/dest/file1.txt
存在。 - Mureinik