我正在尝试使用 commons-vfs 作为文件系统包装器,以便更轻松地对需要接触文件系统的一些代码进行单元测试。现在我刚刚熟悉 API。我想做的是创建一个虚拟文件系统,并添加几个文件(一个文件夹,然后将该文件夹中的一个文件添加到根目录)。
这是我编写的用于测试 API 的测试类:
public class CommonsVfsLearningSpikeTest extends Base {
FileSystemManager fsManager;
FileObject rootVFS;
@Before public void createFixture() throws Exception{
this.fsManager = VFS.getManager();
this.rootVFS = fsManager.createVirtualFileSystem("rootVfs");
}
@Test public void testCreationOfDefaultFileSystem() throws Exception {
assertNotNull(fsManager);
}
@Test public void testCreationOfVFS() throws Exception {
//root file has an empty base name
assertEquals("", rootVFS.getName().getBaseName());
}
@Test public void testCreationOfChildrenFiles() throws Exception {
FileObject childFolder = rootVFS.resolveFile("childFolder");
childFolder.createFolder();
assertNotNull(childFolder );
FileObject childFile = rootVFS.resolveFile("childFolder/childFile");
childFile.createFile();
assertNotNull(childFile);
}
}
目前我收到以下错误:
[junit] Testcase: testCreationOfChildrenFiles(com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest): Caused an ERROR [junit] Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". [junit] org.apache.commons.vfs.FileSystemException: Incorrect file system URI "file:///" in name "file:///rootVfs/childFolder", was expecting "/rootVfs/". [junit] at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:274) [junit] at org.apache.commons.vfs.provider.AbstractFileSystem.resolveFile(AbstractFileSystem.java:267) [junit] at org.apache.commons.vfs.provider.AbstractFileObject.resolveFile(AbstractFileObject.java:670) [junit] at com.usengineeringsolutions.bridgewatch.vfs.CommonsVfsLearningSpikeTest.testCreationOfChildrenFiles(CommonsVfsLearningSpikeTest.java:27) [junit] [junit]