### Question:
AbstractNameSetOnlyPermission extends AbstractNameOnlyPermission<This> { public AbstractPermissionCollection newPermissionCollection() { return NameSetPermissionCollection.newInstance(this, nameEnumeration); } protected  AbstractNameSetOnlyPermission(final String name, final StringEnumeration nameEnumeration); AbstractPermissionCollection newPermissionCollection(); final boolean nameEquals(final String name); final boolean impliesName(final String name);  }### Answer:
@Test public void testCollection() { final AbstractPermissionCollection collection = new SomePermission("name1").newPermissionCollection(); assertEquals(0, collection.size()); Iterator<Permission> iterator = collection.iterator(); assertFalse(iterator.hasNext()); collection.add(new SomePermission("name1")); collection.add(new SomePermission("name2")); assertEquals(2, collection.size()); iterator = collection.iterator(); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertTrue(iterator.hasNext()); assertNotNull(iterator.next()); assertFalse(iterator.hasNext()); assertTrue(collection.implies(new SomePermission("name1"))); assertTrue(collection.implies(new SomePermission("name2"))); assertFalse(collection.implies(new SomePermission("name3"))); assertFalse(collection.implies(new SomePermission("*"))); assertFalse(collection.implies(new SomeOtherPermission("name1"))); assertFalse(collection.implies(new SomeOtherPermission("name3"))); assertFalse(collection.implies(new SomeOtherPermission("*"))); collection.add(new SomePermission("*")); assertEquals(1, collection.size()); assertTrue(collection.implies(new SomePermission("name1"))); assertTrue(collection.implies(new SomePermission("name2"))); assertTrue(collection.implies(new SomePermission("name3"))); assertTrue(collection.implies(new SomePermission("*"))); assertFalse(collection.implies(new SomeOtherPermission("name1"))); assertFalse(collection.implies(new SomeOtherPermission("name3"))); assertFalse(collection.implies(new SomeOtherPermission("*"))); iterator = collection.iterator(); assertTrue(iterator.hasNext()); assertEquals(new SomePermission("*"), iterator.next()); assertFalse(iterator.hasNext()); }
@Test public void testSerialization() { SomePermission perm = new SomePermission("name1"); SerializedPermission obj = (SerializedPermission) perm.writeReplace(); SomePermission resolved = (SomePermission) obj.readResolve(); assertEquals(perm, resolved); AbstractPermissionCollection permissions = perm.newPermissionCollection(); permissions.add(new SomePermission("name2")); SerializedPermissionCollection obj2 = (SerializedPermissionCollection) permissions.writeReplace(); AbstractPermissionCollection resolvedCollection = (AbstractPermissionCollection) obj2.readResolve(); assertTrue(PermissionUtil.equals(permissions, resolvedCollection)); Iterator<Permission> iterator = resolvedCollection.iterator(); assertTrue(iterator.hasNext()); assertEquals(new SomePermission("name2"), iterator.next()); assertFalse(iterator.hasNext()); }