HierarchicalDirectoryBuilder implements DirectoryBuilder { @Override public File getDirectory(String filename) { return getUnused(filename); } HierarchicalDirectoryBuilder(File root, int max_occurence, int maxItems); @Override File getDirectory(String filename); File getRoot(); static final String DHUS_ENTRY_NAME; }
@Test public void getDirectory() throws IOException { HierarchicalDirectoryBuilder db=new HierarchicalDirectoryBuilder(tmp,3,5); File f = db.getDirectory (); Assert.assertTrue (f.exists ()); String fileName = "file"; f = db.getDirectory (fileName); File file = new File (f, fileName); file.createNewFile (); File f2 = db.getDirectory (fileName); Assert.assertNotEquals (f.getAbsolutePath (), f2.getAbsolutePath ()); }
@Test public void getDirectoryChange() throws IOException { HierarchicalDirectoryBuilder db=new HierarchicalDirectoryBuilder(tmp,3,5); File f = db.getDirectory (); f = db.getDirectory (); for (int i = 0; i < 5; i++) { File file = new File (f, "file"+i); file.createNewFile (); } File f2 = db.getDirectory (); Assert.assertNotEquals (f.getAbsolutePath (), f2.getAbsolutePath ()); }
@Test public void getDirectoryDepth() throws IOException { HierarchicalDirectoryBuilder db=new HierarchicalDirectoryBuilder(tmp,3,5); for (int j = 0; j < 10; j++) { File f = db.getDirectory (); f = db.getDirectory (); for (int i = 0; i < 5; i++) { File file = new File (f, "file"+i); file.createNewFile (); } } File f2 = db.getDirectory (); Assert.assertTrue (f2.getAbsolutePath ().contains ("x0/x1")); }