UserMapper implements Function<LdapEntry, UserImpl> { @Override public UserImpl apply(LdapEntry entry) { return new UserImpl( entry.getAttribute(idAttr) != null ? entry.getAttribute(idAttr).getStringValue() : null, entry.getAttribute(mailAttr) != null ? entry.getAttribute(mailAttr).getStringValue() : null, entry.getAttribute(nameAttr) != null ? entry.getAttribute(nameAttr).getStringValue() : null); } UserMapper(String userIdAttr, String userNameAttr, String userEmailAttr); @Override UserImpl apply(LdapEntry entry);  }
@Test public void testMappingFromLdapAttributesToUser() throws Exception { final LdapEntry entry = new LdapEntry("uid=user123,dc=codenvy,dc=com"); entry.addAttribute(new LdapAttribute("uid", "user123")); entry.addAttribute(new LdapAttribute("cn", "name")); entry.addAttribute(new LdapAttribute("mail", "user@codenvy.com")); entry.addAttribute(new LdapAttribute("sn", "LastName")); final UserMapper userMapper = new UserMapper("uid", "cn", "mail"); final UserImpl user = userMapper.apply(entry); assertEquals(user, new UserImpl("user123", "user@codenvy.com", "name")); }