Subject subject = new Subject();
subject.getPrincipals().add(principal);
SubjectDomainCombiner combiner = new SubjectDomainCombiner(subject);
ProtectionDomain[] pd;
// test case: both parameters are null
assertNull(combiner.combine(null, null));
// test case: check assigned principals
URL url = new URL("file://foo.txt");
CodeSource source = new CodeSource(url, (Certificate[]) null);
PermissionCollection permissions = new Permissions();
ClassLoader classLoader = new URLClassLoader(new URL[] { url });
Principal p = new Principal() {
public String getName() {
return "p";
}
};
Principal[] principals = new Principal[] { p };
ProtectionDomain domain = new ProtectionDomain(source, permissions,
classLoader, principals);
pd = combiner.combine(new ProtectionDomain[] { domain }, null);
assertSame("CodeSource", source, pd[0].getCodeSource());
assertSame("PermissionCollection", permissions, pd[0]
.getPermissions());
assertSame("ClassLoader", classLoader, pd[0].getClassLoader());
assertEquals("Size", 1, pd[0].getPrincipals().length);
assertSame("Principal", principal, (pd[0].getPrincipals())[0]);
// test case: check inherited domains
pd = combiner.combine(null, new ProtectionDomain[] { domain });
assertSame("Inherited domain", domain, pd[0]);
}