### Question:
DefaultAuthenticationPolicy implements AuthenticationPolicy { protected boolean isAnonymousAccount(Subject subject) { PrincipalCollection pc = subject.getPrincipals(); return pc != null && matches(pc, anonymousAccountUsername, anonymousAccountRealmName); }  boolean isVmConnectionAuthenticationRequired(); void setVmConnectionAuthenticationRequired(boolean vmConnectionAuthenticationRequired); String getSystemAccountUsername(); void setSystemAccountUsername(String systemAccountUsername); String getSystemAccountRealmName(); void setSystemAccountRealmName(String systemAccountRealmName); boolean isAnonymousAccessAllowed(); void setAnonymousAccessAllowed(boolean anonymousAccessAllowed); String getAnonymousAccountUsername(); void setAnonymousAccountUsername(String anonymousAccountUsername); String getAnonymousAccountRealmName(); void setAnonymousAccountRealmName(String anonymousAccountRealmName); @Override boolean isAuthenticationRequired(SubjectConnectionReference conn); @Override void customizeSubject(Subject.Builder subjectBuilder, ConnectionReference conn);  }### Answer:
@Test public void testIsAnonymousAccount() { Subject subject = new SubjectAdapter() { @Override public PrincipalCollection getPrincipals() { return new SimplePrincipalCollection("anonymous", "iniRealm"); } }; assertTrue(policy.isAnonymousAccount(subject)); }
@Test public void testIsAnonymousAccountWithNullPrincipals() { assertFalse(policy.isAnonymousAccount(new SubjectAdapter())); }