FSFileResource implements FileResource { @Override public String getResourceId() { return relativePath; } @Deprecated  FSFileResource(File inputRoot, File fullPath);  FSFileResource(Path inputRoot, Path fullPath); @Override String getResourceId(); @Override Metadata getMetadata(); @Override InputStream openInputStream();  }
@Test public void testRelativization() throws Exception { Path root = Paths.get("root/abc/def").toAbsolutePath(); Path allegedChild = Paths.get(root.getParent().getParent().toAbsolutePath().toString()); try { FSFileResource r = new FSFileResource(root, allegedChild); fail("should have had assertion error: alleged child not actually child of root"); } catch (AssertionError e) { } root = Paths.get("root/abc/def"); Path child = Paths.get(root.toString(), "ghi/jkl/lmnop.doc"); FSFileResource r = new FSFileResource(root, child); String id = r.getResourceId(); assertTrue(id.startsWith("ghi")); assertTrue(id.endsWith("lmnop.doc")); }