### Question:
AmbariLdapDataPopulator { protected LdapTemplate loadLdapTemplate() { final LdapServerProperties properties = getConfiguration().getLdapServerProperties(); if (ldapTemplate == null || !properties.equals(getLdapProperties())) { LOG.info("Reloading properties"); ldapServerProperties = properties; final LdapContextSource ldapContextSource = createLdapContextSource(); ldapContextSource.setPooled(true); final List<String> ldapUrls = ldapServerProperties.getLdapUrls(); ldapContextSource.setUrls(ldapUrls.toArray(new String[ldapUrls.size()])); if (!ldapServerProperties.isAnonymousBind()) { ldapContextSource.setUserDn(ldapServerProperties.getManagerDn()); ldapContextSource.setPassword(ldapServerProperties.getManagerPassword()); } if (ldapServerProperties.isUseSsl() && ldapServerProperties.isDisableEndpointIdentification()) { System.setProperty(SYSTEM_PROPERTY_DISABLE_ENDPOINT_IDENTIFICATION, "true"); LOG.info("Disabled endpoint identification"); } else { System.clearProperty(SYSTEM_PROPERTY_DISABLE_ENDPOINT_IDENTIFICATION); LOG.info("Removed endpoint identification disabling"); } ldapContextSource.setReferral(ldapServerProperties.getReferralMethod()); try { ldapContextSource.afterPropertiesSet(); } catch (Exception e) { LOG.error("LDAP Context Source not loaded ", e); throw new UsernameNotFoundException("LDAP Context Source not loaded", e); } ldapTemplate = createLdapTemplate(ldapContextSource); ldapTemplate.setIgnorePartialResultException(true); } return ldapTemplate; } @Inject  AmbariLdapDataPopulator(Provider<AmbariLdapConfiguration> configurationProvider, Users users); boolean isLdapEnabled(); LdapSyncDto getLdapSyncInfo(); LdapBatchDto synchronizeAllLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeAllLdapUsers(LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapGroups(Set<String> groups, LdapBatchDto batchInfo); LdapBatchDto synchronizeLdapUsers(Set<String> users, LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapGroups(LdapBatchDto batchInfo); LdapBatchDto synchronizeExistingLdapUsers(LdapBatchDto batchInfo);  }### Answer:
@SuppressWarnings("unchecked") @Test public void testReferralMethod() { final Provider<AmbariLdapConfiguration> configurationProvider = createNiceMock(Provider.class); final AmbariLdapConfiguration configuration = createNiceMock(AmbariLdapConfiguration.class); final Users users = createNiceMock(Users.class); LdapContextSource ldapContextSource = createNiceMock(LdapContextSource.class); List<String> ldapUrls = Collections.singletonList("url"); LdapTemplate ldapTemplate = createNiceMock(LdapTemplate.class); LdapServerProperties ldapServerProperties = createNiceMock(LdapServerProperties.class); expect(configurationProvider.get()).andReturn(configuration).anyTimes(); expect(configuration.getLdapServerProperties()).andReturn(ldapServerProperties).anyTimes(); expect(ldapServerProperties.getLdapUrls()).andReturn(ldapUrls).anyTimes(); expect(ldapServerProperties.getReferralMethod()).andReturn("follow"); ldapContextSource.setReferral("follow"); ldapTemplate.setIgnorePartialResultException(true); replay(ldapTemplate, configurationProvider, configuration, ldapServerProperties, ldapContextSource); final TestAmbariLdapDataPopulator populator = new TestAmbariLdapDataPopulator(configurationProvider, users); populator.setLdapContextSource(ldapContextSource); populator.setLdapTemplate(ldapTemplate); populator.setLdapServerProperties(ldapServerProperties); populator.loadLdapTemplate(); verify(ldapTemplate, configurationProvider, configuration, ldapServerProperties, ldapContextSource); }