### Question:
DefaultLdapConfigurationService implements LdapConfigurationService { @Override public void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException { LOGGER.info("Trying to connect to the LDAP server using provided configuration..."); LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration); Boolean isConnected = ldapConnectionTemplate.execute(new ConnectionCallback<Boolean>() { @Override public Boolean doWithConnection(LdapConnection connection) throws LdapException { return connection.isConnected() && connection.isAuthenticated(); } }); if (!isConnected) { LOGGER.error("Could not connect to the LDAP server"); throw new AmbariLdapException("Could not connect to the LDAP server. Configuration: " + ambariLdapConfiguration); } LOGGER.info("Successfully conencted to the LDAP."); } @Inject  DefaultLdapConfigurationService(); @Override void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration); @Override String checkUserAttributes(String testUserName, String testPassword, AmbariLdapConfiguration ambariLdapConfiguration); @Override Set<String> checkGroupAttributes(String userDn, AmbariLdapConfiguration ambariLdapConfiguration);  }### Answer:
@Test public void testShouldConnectionCheckSucceedWhenConnectionCallbackSucceeds() throws Exception { AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(Maps.newHashMap()); EasyMock.expect(ldapConnectionTemplateMock.execute(EasyMock.anyObject(ConnectionCallback.class))).andReturn(Boolean.TRUE); EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock); replayAll(); ldapConfigurationService.checkConnection(ambariLdapConfiguration); }
@Test(expected = AmbariLdapException.class) public void testShouldConnectionCheckFailWhenConnectionCallbackFails() throws Exception { AmbariLdapConfiguration ambariLdapConfiguration = new AmbariLdapConfiguration(Maps.newHashMap()); EasyMock.expect(ldapConnectionTemplateMock.execute(EasyMock.anyObject(ConnectionCallback.class))).andReturn(Boolean.FALSE); EasyMock.expect(ldapConnectionTemplateFactory.create(ambariLdapConfiguration)).andReturn(ldapConnectionTemplateMock); replayAll(); ldapConfigurationService.checkConnection(ambariLdapConfiguration); }