### Question:
AmbariLdapFacade implements LdapFacade { @Override public Set<String> checkLdapAttributes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration) throws AmbariLdapException { String userName = getTestUserNameFromParameters(parameters); String testUserPass = getTestUserPasswordFromParameters(parameters); if (null == userName) { throw new IllegalArgumentException("No test user available for testing LDAP attributes"); } LOGGER.info("Testing LDAP user attributes with test user: {}", userName); String userDn = ldapConfigurationService.checkUserAttributes(userName, testUserPass, ldapConfiguration); LOGGER.info("Testing LDAP group attributes with test user dn: {}", userDn); return ldapConfigurationService.checkGroupAttributes(userDn, ldapConfiguration); } @Inject  AmbariLdapFacade(); @Override void checkConnection(AmbariLdapConfiguration ambariLdapConfiguration); @Override AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration); @Override Set<String> checkLdapAttributes(Map<String, Object> parameters, AmbariLdapConfiguration ldapConfiguration);  }### Answer:
@Test public void testShouldLdapAttributesCheckDelegateToTheRightServiceCalls() throws Exception { Map<String, Object> parameters = Maps.newHashMap(); parameters.put(AmbariLdapFacade.Parameters.TEST_USER_NAME.getParameterKey(), "testUser"); parameters.put(AmbariLdapFacade.Parameters.TEST_USER_PASSWORD.getParameterKey(), "testPassword"); Capture<String> testUserCapture = Capture.newInstance(); Capture<String> testPasswordCapture = Capture.newInstance(); Capture<String> userDnCapture = Capture.newInstance(); EasyMock.expect(ldapConfigurationServiceMock.checkUserAttributes(EasyMock.capture(testUserCapture), EasyMock.capture(testPasswordCapture), EasyMock.capture(ambariLdapConfigurationCapture))).andReturn("userDn"); EasyMock.expect(ldapConfigurationServiceMock.checkGroupAttributes(EasyMock.capture(userDnCapture), EasyMock.capture(ambariLdapConfigurationCapture))).andReturn(Sets.newHashSet("userGroup")); replayAll(); Set<String> testUserGroups = ldapFacade.checkLdapAttributes(parameters, ambariLdapConfiguration); Assert.assertEquals("testUser", testUserCapture.getValue()); Assert.assertEquals("testPassword", testPasswordCapture.getValue()); Assert.assertEquals("userDn", userDnCapture.getValue()); Assert.assertTrue(testUserGroups.contains("userGroup")); }
@Test(expected = AmbariLdapException.class) public void testShouldAttributeCheckFailuresResultInAmbariLdapException() throws Exception { Map<String, Object> parameters = Maps.newHashMap(); parameters.put(AmbariLdapFacade.Parameters.TEST_USER_NAME.getParameterKey(), "testUser"); parameters.put(AmbariLdapFacade.Parameters.TEST_USER_PASSWORD.getParameterKey(), "testPassword"); EasyMock.expect(ldapConfigurationServiceMock.checkUserAttributes(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject(AmbariLdapConfiguration.class))).andThrow(new AmbariLdapException("Testing ...")); replayAll(); Set<String> testUserGroups = ldapFacade.checkLdapAttributes(parameters, ambariLdapConfiguration); }