FileUtils { public static String getParentPath( final String path ) { if ( path == null || path.length() == 0 || path.indexOf( '/' ) == -1 ) { throw new IllegalArgumentException(); } else if ( path.equals( PATH_SEPARATOR ) ) { return null; } int index = trimTrailingSlash( path ).lastIndexOf( PATH_SEPARATOR ); if ( index == -1 ) { return null; } else if ( index == 0 ) { return PATH_SEPARATOR; } else { return path.substring( 0, index ); } }  static String idToPath( String pathId ); static boolean closeQuietly( FileInputStream fileInputStream ); static boolean containsReservedCharacter( String path, char[] reserved ); static boolean containsControlCharacters( String path ); static String[] convertCommaSeparatedStringToArray( String stringToConvert ); static String getParentPath( final String path ); static boolean isRootLevelPath( final String path ); static final String PATH_SEPARATOR; static final String ENCODED_PATH_SEPARATOR; }
@Test public void getParentPath_Ok() { assertEquals( null, FileUtils.getParentPath( "/" ) ); assertEquals( "/", FileUtils.getParentPath( "/asdf" ) ); assertEquals( "/", FileUtils.getParentPath( "/asdf/" ) ); assertEquals( "/asdf", FileUtils.getParentPath( "/asdf/ghjk" ) ); assertEquals( "/asdf", FileUtils.getParentPath( "/asdf/ghjk/" ) ); assertEquals( "/asdf/ghjk", FileUtils.getParentPath( "/asdf/ghjk/zxcv" ) ); assertEquals( "/as~!@#$%df/gh^&*()jk/zx_+ ,.cv", FileUtils.getParentPath( "/as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); assertEquals( null, FileUtils.getParentPath( "asdf/" ) ); assertEquals( "asdf", FileUtils.getParentPath( "asdf/ghjk" ) ); assertEquals( "as~!@#$%df/gh^&*()jk/zx_+ ,.cv", FileUtils.getParentPath( "as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); }