@Test
  public void verifyMergingStrategyWithNoncollidingAttributeAdder() throws Exception {
    try (AbstractPrincipalAttributesRepository repository =
        getPrincipalAttributesRepository(TimeUnit.SECONDS.name(), 5)) {
      repository.setMergingStrategy(AbstractPrincipalAttributesRepository.MergingStrategy.ADD);

      assertTrue(repository.getAttributes(this.principal).containsKey("mail"));
      assertEquals(
          repository.getAttributes(this.principal).get("mail").toString(), "*****@*****.**");
    }
  }
  @Test
  public void ensureCachedAttributesWithUpdate() throws Exception {
    try (AbstractPrincipalAttributesRepository repository =
        getPrincipalAttributesRepository(TimeUnit.SECONDS.name(), 5)) {
      assertEquals(repository.getAttributes(this.principal).size(), this.attributes.size());
      assertTrue(repository.getAttributes(this.principal).containsKey("mail"));

      attributes.clear();
      assertTrue(repository.getAttributes(this.principal).containsKey("mail"));
    }
  }
 @Test
 public void checkExpiredCachedAttributes() throws Exception {
   assertEquals(this.principal.getAttributes().size(), 1);
   try (AbstractPrincipalAttributesRepository repository =
       getPrincipalAttributesRepository(TimeUnit.MILLISECONDS.name(), 100)) {
     assertEquals(repository.getAttributes(this.principal).size(), this.attributes.size());
     assertTrue(repository.getAttributes(this.principal).containsKey("mail"));
     Thread.sleep(200);
     this.attributes.remove("mail");
     assertTrue(repository.getAttributes(this.principal).containsKey("a2"));
     assertFalse(repository.getAttributes(this.principal).containsKey("mail"));
   }
 }
  @Test
  public void verifyMergingStrategyWithMultivaluedAttributeMerger() throws Exception {
    try (AbstractPrincipalAttributesRepository repository =
        getPrincipalAttributesRepository(TimeUnit.SECONDS.name(), 5)) {
      repository.setMergingStrategy(
          AbstractPrincipalAttributesRepository.MergingStrategy.MULTIVALUED);

      assertTrue(repository.getAttributes(this.principal).get("mail") instanceof List);

      final List<?> values = (List) repository.getAttributes(this.principal).get("mail");
      assertTrue(values.contains("*****@*****.**"));
      assertTrue(values.contains("*****@*****.**"));
    }
  }