private static String getElement(String path, int index) { int count = 0; for (String p : PathUtils.elements(path)) { if (index == count++) { return p; } } fail(); return ""; }
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 } } }
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);
@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(parent + "/" + child, PathUtils.concat(parent + "/", "/" + child)); if (assertsEnabled) { fail(); fail(); } catch (IllegalArgumentException e) { try { PathUtils.concat("/" + parent, "/" + child); fail(); } catch (IllegalArgumentException e) { PathUtils.concat("", "//"); if (assertsEnabled) { fail(); PathUtils.concat("/", "/"); if (assertsEnabled) { fail(); try { PathUtils.relativize("x/y", "y/x"); fail(); } catch (IllegalArgumentException e) {