/** * Validate parent resolution is correct. * * @param child Child path. * @param parent Expected parent path. */ private void validateParent(String child, @Nullable String parent) { assertEquals(parent == null ? null : new IgfsPath(parent), new IgfsPath(child).parent()); }
/** * Test public methods of igfs path. * * @throws Exception In case of any exception. */ @Test public void testMethods() throws Exception { IgfsPath path = new IgfsPath("/a/s/d/f"); validateParent("/a/s/d/f", "/a/s/d"); validateParent("/a/s/d", "/a/s"); validateParent("/a/s", "/a"); validateParent("/a", "/"); validateParent("/", null); assertEquals(new IgfsPath("/a/s/d/f-2"), path.suffix("-2")); assertEquals(Arrays.asList("a", "s", "d", "f"), path.components()); assertEquals(4, path.depth()); assertEquals(3, path.parent().depth()); assertEquals("f", path.name()); assertEquals(path, mu(path)); IgfsPath parent = path.parent(); assertTrue(path.compareTo(new IgfsPath(parent, "e")) > 0); assertTrue(path.compareTo(new IgfsPath(parent, "g")) < 0); }
/** * Test igfs path constructors. * * @throws Exception In case of any exception. */ @SuppressWarnings("TooBroadScope") @Test public void testConstructors() throws Exception { String pathStr = "///"; URI uri = URI.create(pathStr); IgfsPath path = new IgfsPath(uri); Class nullUri = URI.class; Class nullStr = String.class; Class nullPath = IgfsPath.class; expectConstructorThrows(NullPointerException.class, nullUri); expectConstructorThrows(IllegalArgumentException.class, nullStr); expectConstructorThrows(IllegalArgumentException.class, nullStr, nullStr, nullStr); expectConstructorThrows(NullPointerException.class, nullPath, nullStr); expectConstructorThrows(NullPointerException.class, nullPath, nullUri); String name = "with space in path.txt"; assertEquals(name, new IgfsPath(path, name).name()); }