public static FilePermissions fromOctalString(String octalPermissions) {
    if (!octalPermissions.matches(OCTAL_PATTERN)) {
      throw new IllegalArgumentException(
          "octalPermissions must be a 3-digit octal number (000-777)");
    }
    return new FilePermissions(Integer.parseInt(octalPermissions, 8));
  }
@Test
  public void testFromOctalString() {
    Assert.assertEquals(new FilePermissions(0777), FilePermissions.fromOctalString("777"));
    Assert.assertEquals(new FilePermissions(0000), FilePermissions.fromOctalString("000"));
    Assert.assertEquals(new FilePermissions(0123), FilePermissions.fromOctalString("123"));
    Assert.assertEquals(new FilePermissions(0755), FilePermissions.fromOctalString("755"));
    Assert.assertEquals(new FilePermissions(0644), FilePermissions.fromOctalString("644"));

    ImmutableList<String> badStrings = ImmutableList.of("abc", "-123", "777444333", "987", "3");
    for (String badString : badStrings) {
      try {
        FilePermissions.fromOctalString(badString);
        Assert.fail();
      } catch (IllegalArgumentException ex) {
        Assert.assertEquals(
            "octalPermissions must be a 3-digit octal number (000-777)", ex.getMessage());
      }
    }
  }