### Question:
AmbariLdapFacade implements LdapFacade { @Override public AmbariLdapConfiguration detectAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException { LOGGER.info("Detecting LDAP configuration attributes ..."); try { LOGGER.info("Detecting user attributes ...."); ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapUserAttributes(ambariLdapConfiguration); LOGGER.info("Detecting group attributes ...."); ambariLdapConfiguration = ldapAttributeDetectionService.detectLdapGroupAttributes(ambariLdapConfiguration); LOGGER.info("Attribute detection finished."); return ambariLdapConfiguration; } catch (Exception e) { LOGGER.error("Error during LDAP attribute detection", e); throw new AmbariLdapException(e); } } @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 testShouldLdapAttributeDetectionDelegateToTheRightServiceCalls() throws Exception { Map<String, String> userConfigMap = Maps.newHashMap(); userConfigMap.put(AmbariServerConfigurationKey.USER_NAME_ATTRIBUTE.key(), "uid"); AmbariLdapConfiguration userAttrDecoratedConfig = new AmbariLdapConfiguration(userConfigMap); Map<String, String> groupConfigMap = Maps.newHashMap(userConfigMap); groupConfigMap.put(AmbariServerConfigurationKey.GROUP_NAME_ATTRIBUTE.key(), "dn"); AmbariLdapConfiguration groupAttrDecoratedConfig = new AmbariLdapConfiguration(groupConfigMap); Capture<AmbariLdapConfiguration> userAttrDetectionConfigCapture = Capture.newInstance(); Capture<AmbariLdapConfiguration> groupAttrDetectionConfigCapture = Capture.newInstance(); EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapUserAttributes(EasyMock.capture(userAttrDetectionConfigCapture))) .andReturn(userAttrDecoratedConfig); EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapGroupAttributes(EasyMock.capture(groupAttrDetectionConfigCapture))) .andReturn(groupAttrDecoratedConfig); replayAll(); AmbariLdapConfiguration detected = ldapFacade.detectAttributes(ambariLdapConfiguration); Assert.assertEquals("User attribute detection called with the wrong configuration", ambariLdapConfiguration, userAttrDetectionConfigCapture.getValue()); Assert.assertEquals("Group attribute detection called with the wrong configuration", userAttrDecoratedConfig, groupAttrDetectionConfigCapture.getValue()); Assert.assertEquals("Attribute detection returned an invalid configuration", groupAttrDecoratedConfig, detected); }
@Test(expected = AmbariLdapException.class) public void testShouldAttributeDetectionFailuresResultInAmbariLdapException() throws Exception { EasyMock.expect(ldapAttributeDetectionServiceMock.detectLdapUserAttributes(EasyMock.anyObject(AmbariLdapConfiguration.class))) .andThrow(new AmbariLdapException("Testing ...")); replayAll(); ldapFacade.detectAttributes(ambariLdapConfiguration); }