@Test
public void testFsPermission() {

  String symbolic = "-rwxrwxrwx";
  for(int i = 0; i < (1 << 10); i++) {
    StringBuilder b = new StringBuilder("----------");
    String binary = String.format("%11s", Integer.toBinaryString(i));
    String permBinary = binary.substring(2, binary.length());
    int len = permBinary.length();
    for(int j = 0; j < len; j++) {
      if (permBinary.charAt(j) == '1') {
        int k = 9 - (len - 1 - j);
        b.setCharAt(k, symbolic.charAt(k));
      }
    }
    // Check for sticky bit.
    if (binary.charAt(1) == '1') {
      char replacement = b.charAt(9) == 'x' ? 't' : 'T';
      b.setCharAt(9, replacement);
    }
    assertEquals(i, FsPermission.valueOf(b.toString()).toShort());
  }
}