@Test
    void testCaching() {
        val cacheMap = new HashMap<Serializable, Set<PersonAttributes>>();

        var dao = new CachingPersonAttributeDaoImpl();
        dao.setCachedPersonAttributesDao(stubDao);
        dao.setUsernameAttributeProvider(new SimpleUsernameAttributeProvider(DEFAULT_ATTR));
        dao.setUserInfoCache(cacheMap);
        dao.afterPropertiesSet();

        assertEquals(0, cacheMap.size());

        var result = dao.getPerson("edalquist");
        validateUser1(result.getAttributes());
        assertEquals(1, cacheMap.size());

        result = dao.getPerson("edalquist");
        validateUser1(result.getAttributes());
        assertEquals(1, cacheMap.size());

        result = dao.getPerson("nobody");
        assertNull(result);
        assertEquals(1, cacheMap.size());

        result = dao.getPerson("edalquist");
        validateUser1(result.getAttributes());
        assertEquals(1, cacheMap.size());

        dao.setCacheNullResults(true);
        result = dao.getPerson("nobody");
        assertNull(result);
        assertEquals(2, cacheMap.size());

        result = dao.getPerson("edalquist");
        validateUser1(result.getAttributes());
        assertEquals(2, cacheMap.size());

        val queryMap = new HashMap<String, List<Object>>();
        queryMap.put(DEFAULT_ATTR, List.of("edalquist"));
        queryMap.put("name.first", List.of("Eric"));
        queryMap.put("name.last", List.of("Dalquist"));

        var resultSet = dao.getPeopleWithMultivaluedAttributes(queryMap);
        assertEquals(1, resultSet.size());
        validateUser1(resultSet.iterator().next().getAttributes());
        assertEquals(2, cacheMap.size());

        dao.removeUserAttributesMultivaluedSeed(queryMap);
        assertEquals(1, cacheMap.size());

        dao.removeUserAttributes("nobody");
        assertEquals(0, cacheMap.size());
    }
This is {@link CachingPersonAttributeDaoTests}.

@author Misagh Moayyed
@since 7.1.0
support/cas-server-support-person-directory-core/src/test/java/org/apereo/cas/persondir/CachingPersonAttributeDaoTests.java