PathUtils { public static String ensureNotEndingSlash(String path) { Objects.requireNonNull(path, "path must not be null"); if ("".equals(path)) { return path; } final int length = path.length(); return path.charAt(length - 1) == '/' ? path.substring(0, length - 1) : path; }  static String noStartingSlash(String path); static boolean hasStartingSlash(String path); static String noPrefix(String path, String prefix); static String ensureStartingSlash(String path); static String ensureEndingSlash(String path); static String ensureNotEndingSlash(String path); static String normalizePath(String path);  }
@Test public void ensureNotEndingSlash() { assertThat(PathUtils.ensureNotEndingSlash("foo/"), is("foo")); assertThat(PathUtils.ensureNotEndingSlash("/foo/"), is("/foo")); assertThat(PathUtils.ensureNotEndingSlash("/"), is("")); assertThat(PathUtils.ensureNotEndingSlash(""), is("")); }