### Question:
ODLJndiLdapRealm extends DefaultLdapRealm { @Override protected AuthorizationInfo queryForAuthorizationInfo(PrincipalCollection principals, LdapContextFactory ldapContextFactory) throws NamingException { AuthorizationInfo authorizationInfo = null; try { final String username = getUsername(principals); final LdapContext ldapContext = ldapContextFactory.getSystemLdapContext(); final Set<String> roleNames; try { roleNames = getRoleNamesForUser(username, ldapContext); authorizationInfo = buildAuthorizationInfo(roleNames); } finally { LdapUtils.closeContext(ldapContext); } } catch (ClassCastException e) { LOG.error("Unable to extract a valid user", e); } return authorizationInfo; } ODLJndiLdapRealm(); static String getUsername(AuthenticationToken token); static AuthorizationInfo buildAuthorizationInfo(final Set<String> roleNames); @Override String getUserDnSuffix(); void setSearchBase(final String searchBase); void setLdapAttributeForComparison(final String ldapAttributeForComparison); void setGroupRolesMap(final Map<String, String> groupRolesMap);  }### Answer:
@Test public void testQueryForAuthorizationInfoPrincipalCollectionLdapContextFactory() throws NamingException { LdapContext ldapContext = mock(LdapContext.class); when( ldapContext.search((String) any(), (String) any(), any())).thenReturn(new TestNamingEnumeration()); LdapContextFactory ldapContextFactory = mock(LdapContextFactory.class); when(ldapContextFactory.getSystemLdapContext()).thenReturn(ldapContext); AuthorizationInfo authorizationInfo = new ODLJndiLdapRealm().queryForAuthorizationInfo( new TestPrincipalCollection("testuser"), ldapContextFactory); assertNotNull(authorizationInfo); assertFalse(authorizationInfo.getRoles().isEmpty()); assertTrue(authorizationInfo.getRoles().contains("engineering")); }