### Question:
LayerDefinitionParser implements CommandLine.ITypeConverter<FileEntriesLayer> { @VisibleForTesting static FilePermissionsProvider parsePermissionsDirective(String directive) { if ("actual".equals(directive)) { return new ActualPermissionsProvider(); } String[] spec = directive.split(":", -1); FilePermissions filesPermission = FilePermissions.fromOctalString(spec[0]); FilePermissions directoriesPermission = FilePermissions.DEFAULT_FOLDER_PERMISSIONS; if (spec.length > 1) { directoriesPermission = FilePermissions.fromOctalString(spec[1]); } return new FixedPermissionsProvider(filesPermission, directoriesPermission); }  @Override FileEntriesLayer convert(String layerDefinition);  }### Answer:
@Test public void testParsePermissionsDirective_actual() { MatcherAssert.assertThat( LayerDefinitionParser.parsePermissionsDirective("actual"), CoreMatchers.instanceOf(ActualPermissionsProvider.class)); }
@Test public void testParsePermissionsDirective_fileOnly() { FilePermissionsProvider provider = LayerDefinitionParser.parsePermissionsDirective("555"); MatcherAssert.assertThat(provider, CoreMatchers.instanceOf(FixedPermissionsProvider.class)); Assert.assertEquals( 0555, ((FixedPermissionsProvider) provider).filePermissions.getPermissionBits()); Assert.assertSame( FilePermissions.DEFAULT_FOLDER_PERMISSIONS, ((FixedPermissionsProvider) provider).directoryPermissions); }
@Test public void testParsePermissionsDirective_fileOAndDirectory() { FilePermissionsProvider provider = LayerDefinitionParser.parsePermissionsDirective("555:666"); MatcherAssert.assertThat(provider, CoreMatchers.instanceOf(FixedPermissionsProvider.class)); Assert.assertEquals( 0555, ((FixedPermissionsProvider) provider).filePermissions.getPermissionBits()); Assert.assertEquals( 0666, ((FixedPermissionsProvider) provider).directoryPermissions.getPermissionBits()); }
@Test public void testParsePermissionsDirective_nonOctal() { try { LayerDefinitionParser.parsePermissionsDirective("811:922"); Assert.fail(); } catch (RuntimeException ex) { MatcherAssert.assertThat(ex, CoreMatchers.instanceOf(IllegalArgumentException.class)); } }
@Test public void testParsePermissionsDirective_invalid() { try { LayerDefinitionParser.parsePermissionsDirective("invalid"); Assert.fail(); } catch (RuntimeException ex) { MatcherAssert.assertThat(ex, CoreMatchers.instanceOf(IllegalArgumentException.class)); } }