FileUtils { public static boolean isRootLevelPath( final String path ) { if ( path == null || path.length() == 0 || !path.startsWith( PATH_SEPARATOR ) ) { throw new IllegalArgumentException(); } else if ( path.equals( PATH_SEPARATOR ) ) { return true; } else if ( trimTrailingSlash( path ).startsWith( ClientRepositoryPaths.getPublicFolderPath() + PATH_SEPARATOR ) || trimTrailingSlash( path ).startsWith( ClientRepositoryPaths.getHomeFolderPath() + PATH_SEPARATOR ) || trimTrailingSlash( path ).startsWith( ClientRepositoryPaths.getEtcFolderPath() + PATH_SEPARATOR ) ) { return false; } return true; }  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( expected = IllegalArgumentException.class ) public void isRootLevelPath_Null() { FileUtils.isRootLevelPath( null ); }
@Test( expected = IllegalArgumentException.class ) public void isRootLevelPath_Empty() { FileUtils.isRootLevelPath( "" ); }
@Test( expected = IllegalArgumentException.class ) public void isRootLevelPath_NotAbsolute() { FileUtils.isRootLevelPath( "test" ); }
@Test public void isRootLevelPath_True() { assertEquals( true, FileUtils.isRootLevelPath( "/" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/asdf" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/asdf/" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/asdf/ghjk" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/asdf/ghjk/zxcv" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/home6" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/home6/" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/public7" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/public7/" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/etc8" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/etc8/" ) ); }
@Test public void isRootLevelPath_Public() { assertEquals( true, FileUtils.isRootLevelPath( "/public" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/public/" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/public/ghjk" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/public/ghjk/zxcv" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/public/as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); }
@Test public void isRootLevelPath_Home() { assertEquals( true, FileUtils.isRootLevelPath( "/home" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/home/" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/home/ghjk" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/home/ghjk/zxcv" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/home/as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); }
@Test public void isRootLevelPath_Etc() { assertEquals( true, FileUtils.isRootLevelPath( "/etc" ) ); assertEquals( true, FileUtils.isRootLevelPath( "/etc/" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/etc/ghjk" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/etc/ghjk/zxcv" ) ); assertEquals( false, FileUtils.isRootLevelPath( "/etc/as~!@#$%df/gh^&*()jk/zx_+ ,.cv/bnm" ) ); }