@Test public void testConcatRelativePaths() { assertNull(PathUtils.concatRelativePaths("", "", "")); assertNull(PathUtils.concatRelativePaths()); assertEquals("a/b/c", PathUtils.concatRelativePaths("a", "b", "c")); assertEquals("a/b/c", PathUtils.concatRelativePaths("a", "b/c")); assertEquals("a/b/c", PathUtils.concatRelativePaths("a/b/c", "")); assertEquals("a/b/c", PathUtils.concatRelativePaths("a/b", "c")); assertEquals("a/b/c", PathUtils.concatRelativePaths("/", "a", "", "b/c/")); }
@Test public void test() { try { PathUtils.getParentPath("invalid/path/"); if (assertsEnabled) { fail(); } } catch (AssertionFailedError e) { throw e; } catch (AssertionError e) { // expected } try { PathUtils.getName("invalid/path/"); if (assertsEnabled) { fail(); } } catch (AssertionFailedError e) { throw e; } catch (AssertionError e) { // expected } test("parent", "child"); test("x", "y"); }
assertEquals(0, getElementCount("")); assertEquals(0, getElementCount("/")); assertEquals(1, getElementCount(parent)); assertEquals(2, getElementCount(parent + "/" + child)); assertEquals(1, getElementCount("/" + parent)); assertEquals(2, getElementCount("/" + parent + "/" + child)); assertEquals(3, getElementCount("/" + parent + "/" + child + "/" + child)); assertEquals(parent, getElement(parent, 0)); assertEquals(parent, getElement(parent + "/" + child, 0)); assertEquals(child, getElement(parent + "/" + child, 1)); assertEquals(child, getElement(parent + "/" + child + "/" + child + "1", 1)); assertEquals(child + "1", getElement(parent + "/" + child + "/" + child + "1", 2)); assertEquals(parent + "/" + child, PathUtils.concat(parent, child)); try { assertEquals(parent + "/" + child, PathUtils.concat(parent + "/", "/" + child)); if (assertsEnabled) { fail(); assertEquals(parent + "/" + child, PathUtils.concat(parent, "/" + child)); fail(); } catch (IllegalArgumentException e) { assertEquals(parent + "/" + child + "/" + child, PathUtils.concat(parent, child, child)); assertEquals(parent + "/" + child, PathUtils.concat(parent, "", child)); assertEquals(parent + "/" + child, PathUtils.concat(parent, child, "")); assertEquals(child + "/" + child, PathUtils.concat("", child, child)); assertEquals(child, PathUtils.concat("", child, "")); assertEquals(child, PathUtils.concat("", "", child));
public void testOptimizeForExcludes() throws Exception{ Set<String> includes = newHashSet("/a", "/b"); Set<String> excludes = newHashSet("/c"); PathUtils.unifyInExcludes(includes, excludes); assertEquals(newHashSet("/a", "/b"), includes); assertEquals(newHashSet(), excludes); } }
private static String getElement(String path, int index) { int count = 0; for (String p : PathUtils.elements(path)) { if (index == count++) { return p; } } fail(); return ""; }
private static int getElementCount(String path) { int count = 0; for (String p : PathUtils.elements(path)) { assertFalse(PathUtils.isAbsolute(p)); count++; } return count; }
public void testNextSlash() { String path = "/test/a"; int n = PathUtils.getNextSlash(path, 0); assertEquals(0, n); n = PathUtils.getNextSlash(path, n + 1); assertEquals(5, n); n = PathUtils.getNextSlash(path, n + 1); assertEquals(-1, n); }
public void testPathElements() { String[] invalidPaths = new String[]{"//", "/a/", "a/", "/a//", "a//b"}; for (String path: invalidPaths) { try { PathUtils.elements(path); fail(); } catch (AssertionError e) { // expected } } }
public void testOptimizeForIncludes() throws Exception{ Set<String> includes = newHashSet("/a", "/a/b"); Set<String> excludes = newHashSet("/a/b"); PathUtils.unifyInExcludes(includes, excludes); assertEquals("Excludes supercedes include", newHashSet("/a"), includes); assertEquals(newHashSet("/a/b"), excludes); includes = newHashSet("/a", "/a/b/c"); excludes = newHashSet("/a/b"); PathUtils.unifyInExcludes(includes, excludes); assertEquals("Excludes supercedes include", newHashSet("/a"), includes); assertEquals(newHashSet("/a/b"), excludes); includes = newHashSet("/a", "/a/b/c"); excludes = newHashSet(); PathUtils.unifyInExcludes(includes, excludes); assertEquals(newHashSet("/a"), includes); }
@Test public void testGetDepth() { assertEquals(0, PathUtils.getDepth("/")); assertEquals(0, PathUtils.getDepth("")); assertEquals(1, PathUtils.getDepth("/a")); assertEquals(1, PathUtils.getDepth("a")); assertEquals(2, PathUtils.getDepth("/a/b")); assertEquals(2, PathUtils.getDepth("a/b")); }
PathUtils.denotesRoot(invalid); if (assertsEnabled) { fail(); PathUtils.concat(invalid, "x"); if (assertsEnabled) { fail(); PathUtils.concat("/x", invalid); if (assertsEnabled) { fail(); PathUtils.concat("/x", "y", invalid); if (assertsEnabled) { fail(); PathUtils.concat(invalid, "y", "z"); if (assertsEnabled) { fail(); PathUtils.getDepth(invalid); if (assertsEnabled) { fail(); PathUtils.getName(invalid); if (assertsEnabled) { fail(); PathUtils.getNextSlash(invalid, 0);
public void testElements() { String path = "a/b/c"; String[] elementsArray = path.split("/"); Iterable<String> elementsIterable = PathUtils.elements(path); int k = 0; for (String name : elementsIterable) { Assert.assertEquals(elementsArray[k++], name); } assertEquals(3, k); k = 0; for (String name : elementsIterable) { Assert.assertEquals(elementsArray[k++], name); } assertEquals(3, k); }
public void testMore() { String[] paths = { "", "/", "foo", "/foo", "foo/bar", "/foo/bar", "foo/bar/baz", "/foo/bar/baz", "x", "/x", "x/y", "/x/y", "x/y/z", "/x/y/z", }; for (String path : paths) { String parent = PathUtils.getParentPath(path); String name = PathUtils.getName(path); String concat = PathUtils.concat(parent, name); assertEquals("original: " + path + " parent: " + parent + " name: " + name + " concat: " + concat, path, concat); } }