ファイルシステムに触れる必要があるコードの単体テストをより簡単にするために、 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]