@Test
 public void checkCreatingSimplePrincipalWithAttributes() {
   final PrincipalFactory f = new DefaultPrincipalFactory();
   final Principal p =
       f.createPrincipal("uid", Collections.singletonMap("mail", "*****@*****.**"));
   assertEquals(p.getId(), "uid");
   assertEquals(p.getAttributes().size(), 1);
   assertTrue(p.getAttributes().containsKey("mail"));
 }
  /**
   * * Convert principal attributes to person attributes.
   *
   * @param p the principal carrying attributes
   * @return person attributes
   */
  private Map<String, List<Object>> convertPrincipalAttributesToPersonAttributes(
      final Principal p) {
    final Map<String, List<Object>> convertedAttributes = new HashMap<>(p.getAttributes().size());
    final Map<String, Object> principalAttributes = p.getAttributes();

    for (final Map.Entry<String, Object> entry : principalAttributes.entrySet()) {
      final Object values = entry.getValue();
      final String key = entry.getKey();
      if (values instanceof List) {
        convertedAttributes.put(key, (List) values);
      } else {
        convertedAttributes.put(key, Collections.singletonList(values));
      }
    }
    return convertedAttributes;
  }
 @Test
 public void checkCreatingSimplePrincipalWithDefaultRepository() {
   final PrincipalFactory f = new DefaultPrincipalFactory();
   final Principal p = f.createPrincipal("uid");
   assertEquals(p.getId(), "uid");
   assertEquals(p.getAttributes().size(), 0);
 }
 @Test
 public void verifyAttributesWithPrincipal() {
   final PersonDirectoryPrincipalResolver resolver = new PersonDirectoryPrincipalResolver();
   resolver.setAttributeRepository(TestUtils.getAttributeRepository());
   resolver.setPrincipalAttributeName("cn");
   final Credential c = TestUtils.getCredentialsWithSameUsernameAndPassword();
   final Principal p = resolver.resolve(c);
   assertNotNull(p);
   assertNotEquals(p.getId(), TestUtils.CONST_USERNAME);
   assertTrue(p.getAttributes().containsKey("memberOf"));
 }