3
我試圖使用commons-vfs作爲文件系統的包裝,以便更容易地單元測試一些需要接觸文件系統的代碼。現在我只是熟悉API。我想要做的是創建一個虛擬文件系統,並添加一些文件(文件夾,然後將該文件夾中的文件添加到根目錄)。Commons-vfs嘲諷一個文件系統
這是一個測試類,我寫來測試驅動的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]