### Question:
FileUtils { public static int parsePermissions(String permissions) { if (permissions.length() == 3) { return Integer.parseInt(permissions, 8); } else if (permissions.length() == 9) { int perms = parsePermissionGroup(permissions, 0); perms = 8 * perms + parsePermissionGroup(permissions, 3); return 8 * perms + parsePermissionGroup(permissions, 6); } else { throw new IllegalArgumentException("Not a valid permissions string: " + permissions); } } private  FileUtils(); static int permissionsToUmask(int permissions); static String permissionsToUmask(String permissions); static int parsePermissions(String permissions); static final FileAttribute<Set<PosixFilePermission>> OWNER_ONLY_RW; }### Answer:
@Test public void testParsePermissions() { Assert.assertEquals(0000, FileUtils.parsePermissions("---------")); Assert.assertEquals(0750, FileUtils.parsePermissions("rwxr-x---")); Assert.assertEquals(0755, FileUtils.parsePermissions("rwxr-xr-x")); Assert.assertEquals(0700, FileUtils.parsePermissions("rwx------")); Assert.assertEquals(0644, FileUtils.parsePermissions("rw-r--r--")); Assert.assertEquals(0640, FileUtils.parsePermissions("rw-r-----")); Assert.assertEquals(0330, FileUtils.parsePermissions("-wx-wx---")); Assert.assertEquals(0000, FileUtils.parsePermissions("000")); Assert.assertEquals(0750, FileUtils.parsePermissions("750")); Assert.assertEquals(0755, FileUtils.parsePermissions("755")); Assert.assertEquals(0700, FileUtils.parsePermissions("700")); Assert.assertEquals(0644, FileUtils.parsePermissions("644")); Assert.assertEquals(0640, FileUtils.parsePermissions("640")); Assert.assertEquals(0330, FileUtils.parsePermissions("330")); String[] illegalPermissions = new String[] { "0000", "rwx", "00", "drwxrwxrwx", "wrx------", "rwxrwxrws", "write_all", "twx------", "rtx------", "rwt------" }; for (String perm : illegalPermissions) { try { FileUtils.parsePermissions(perm); Assert.fail("Expected IllegalArgumentException for illegal permission string " + perm); } catch (IllegalArgumentException e) { } } String perm = "080"; try { FileUtils.parsePermissions(perm); Assert.fail("Expected NumberFormatException for illegal permission string" + perm); } catch (NumberFormatException e) { } }