ChmodFilePermissions { public static int toBits(Set<PosixFilePermission> permissions) { int bits = 0; for (PosixFilePermission perm : permissions) { bits |= permissionsBitMap.get(perm); } return bits; } private  ChmodFilePermissions(); static Set<PosixFilePermission> toPermissions(int bits); static int toBits(Set<PosixFilePermission> permissions); static String toMode(PermissionChange change, Set<PosixFilePermission> permissions);  }
@Test public void toOwnerBits() { Set<PosixFilePermission> permissions = EnumSet.of( PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE); int bits = ChmodFilePermissions.toBits(permissions); assertThat(bits, equalsBits(0600)); }
@Test public void toGroupBits() { Set<PosixFilePermission> permissions = EnumSet.of( PosixFilePermission.GROUP_READ, PosixFilePermission.GROUP_EXECUTE); int bits = ChmodFilePermissions.toBits(permissions); assertThat(bits, equalsBits(0050)); }
@Test public void toOtherBits() { Set<PosixFilePermission> permissions = EnumSet.of( PosixFilePermission.OTHERS_WRITE, PosixFilePermission.OTHERS_EXECUTE); int bits = ChmodFilePermissions.toBits(permissions); assertThat(bits, equalsBits(0003)); }
@Test public void toCombinedBits() { Set<PosixFilePermission> permissions = EnumSet.of( PosixFilePermission.OWNER_READ, PosixFilePermission.OWNER_WRITE, PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_WRITE, PosixFilePermission.OTHERS_READ); int bits = ChmodFilePermissions.toBits(permissions); assertThat(bits, equalsBits(0724)); }