### Question:
DefaultAuthenticationPolicy implements AuthenticationPolicy { protected boolean isAssumeIdentity(ConnectionReference conn) { return isAnonymousAccessAllowed() || (isSystemConnection(conn) && !isVmConnectionAuthenticationRequired()); }  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 testIsAssumeIdentity() { policy.setAnonymousAccessAllowed(true); assertTrue(policy.isAssumeIdentity(null)); }
@Test public void testIsAssumeIdentityWithSystemConnection() { ConnectionContext ctx = new ConnectionContext(); Connection connection = new Connection() { @Override public Connector getConnector() { return null; } @Override public void dispatchSync(Command message) { } @Override public void dispatchAsync(Command command) { } @Override public Response service(Command command) { return null; } @Override public void serviceException(Throwable error) { } @Override public boolean isSlow() { return false; } @Override public boolean isBlocked() { return false; } @Override public boolean isConnected() { return false; } @Override public boolean isActive() { return false; } @Override public int getDispatchQueueSize() { return 0; } @Override public ConnectionStatistics getStatistics() { return null; } @Override public boolean isManageable() { return false; } @Override public String getRemoteAddress() { return "vm: } @Override public void serviceExceptionAsync(IOException e) { } @Override public String getConnectionId() { return null; } @Override public boolean isNetworkConnection() { return false; } @Override public boolean isFaultTolerantConnection() { return false; } @Override public void updateClient(ConnectionControl control) { } @Override public void start() throws Exception { } @Override public void stop() throws Exception { } @Override public int getActiveTransactionCount() { return 0; } @Override public Long getOldestActiveTransactionDuration() { return null; } }; ctx.setConnection(connection); SubjectConnectionReference sc = new SubjectConnectionReference(ctx, new ConnectionInfo(), new DefaultEnvironment(), new SubjectAdapter()); assertTrue(policy.isAssumeIdentity(sc)); }