BaseCommand { public String getParentPath() { String work = getPath(); if (work.equals("/")) { return work; } if (work.endsWith("/")) { work = work.substring(0, work.length() - 1); } final int lastIndex = work.lastIndexOf('/'); if (lastIndex == -1) { return ""; } else { return work.substring(0, lastIndex) + "/"; } } BaseCommand(); String getPath(); String getEncodedPath(); void setPath(final String path); Revision getRevision(); void setRevision(final Revision revision); void setPegRevision(final Revision pegRevision); Revision getPegRevision(); boolean hasPegRevision(); long getRevisionNumber(); String getTarget(); String getEncodedTarget(); String getParentPath(); String getPathPart(); DirEntryComparator.SortType getSortType(); void setSortType(final DirEntryComparator.SortType sortType); DirEntrySorter.SortMode getSortMode(); void setSortMode(final DirEntrySorter.SortMode sortMode); void setName(final RepositoryName name); RepositoryName getName(); @Override boolean equals(final Object obj); @Override int hashCode(); String createListUrl(); String createShowFileUrl(); String getPathWithTrailingSlash(); @Override String toString();  }
@Test public void testGetParentPath() { final BaseCommand cmd = new BaseCommand(); cmd.setPath("/trunk/src/File.java"); assertEquals("/trunk/src/", cmd.getParentPath()); cmd.setPath("/trunk/src/File.java"); assertEquals("/trunk/src/", cmd.getParentPath()); cmd.setPath("/trunk/src/"); assertEquals("/trunk/", cmd.getParentPath()); cmd.setPath(""); assertEquals("/", cmd.getParentPath()); cmd.setPath("/"); assertEquals("/", cmd.getParentPath()); cmd.setPath(null); assertEquals("/", cmd.getParentPath()); }