LdapUtils { public static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection) { collectAttributeValues(attributes, name, collection, Object.class); } private  LdapUtils(); static void closeContext(DirContext context); static NamingException convertLdapException(javax.naming.NamingException ex); static Class getActualTargetClass(DirContext context); static void collectAttributeValues(Attributes attributes, String name, Collection<Object> collection); static void collectAttributeValues(
            Attributes attributes, String name, Collection<T> collection, Class<T> clazz); static void iterateAttributeValues(Attribute attribute, AttributeValueCallbackHandler callbackHandler); static String convertCompositeNameToString(
			CompositeName compositeName); static LdapName newLdapName(Name name); static LdapName newLdapName(String distinguishedName); static LdapName removeFirst(Name dn, Name pathToRemove); static LdapName prepend(Name dn, Name pathToPrepend); static LdapName emptyLdapName(); static Rdn getRdn(Name name, String key); static Object getValue(Name name, String key); static Object getValue(Name name, int index); static String getStringValue(Name name, int index); static String getStringValue(Name name, String key); static String convertBinarySidToString(byte[] sid); static byte[] convertStringSidToBinary(String string);  }
@Test public void testCollectAttributeValues() { String expectedAttributeName = "someAttribute"; BasicAttribute expectedAttribute = new BasicAttribute(expectedAttributeName); expectedAttribute.add("value1"); expectedAttribute.add("value2"); BasicAttributes attributes = new BasicAttributes(); attributes.put(expectedAttribute); LinkedList list = new LinkedList(); LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list); assertThat(list).hasSize(2); assertThat(list.get(0)).isEqualTo("value1"); assertThat(list.get(1)).isEqualTo("value2"); }
@Test public void testCollectAttributeValuesThrowsExceptionWhenAttributeNotPresent() { String expectedAttributeName = "someAttribute"; BasicAttributes attributes = new BasicAttributes(); LinkedList list = new LinkedList(); try { LdapUtils.collectAttributeValues(attributes, expectedAttributeName, list); fail("NoSuchAttributeException expected"); } catch (NoSuchAttributeException expected) { assertThat(true).isTrue(); } }