FileDirectory { public File getFile(FileReference reference) { ensureRootExist(); File dir = new File(getPath(reference)); if (!dir.exists()) { throw new IllegalArgumentException("File reference '" + reference.toString() + "' with absolute path '" + dir.getAbsolutePath() + "' does not exist."); } if (!dir.isDirectory()) { throw new IllegalArgumentException("File reference '" + reference.toString() + "' with absolute path '" + dir.getAbsolutePath() + "' is not a directory."); } File [] files = dir.listFiles(new Filter()); if (files == null || files.length == 0) { throw new IllegalArgumentException("File reference '" + reference.toString() + "' with absolute path '" + dir.getAbsolutePath() + " does not contain any files"); } return files[0]; } FileDirectory(File rootDir); File getFile(FileReference reference); FileReference addFile(File source); @Override String toString();  }
@Test public void requireThatFileReferenceWithFilesWorks() throws IOException { FileReference foo = createFile("foo"); FileReference bar = createFile("bar"); assertTrue(fileDirectory.getFile(foo).exists()); assertEquals("ea315b7acac56246", foo.value()); assertTrue(fileDirectory.getFile(bar).exists()); assertEquals("2b8e97f15c854e1d", bar.value()); }