@Test
  public void testFrequentlyUsedEviction() {
    // Cache has 4 entries; 2 for LFU and 2 for MFU
    // key is considered as MFU, if its accessCount > 1
    mCache =
        createDummyAdaptiveCountingMemoryCache(
            mParamsSupplier,
            mCacheTrimStrategy,
            mValueDescriptor,
            100,
            1,
            2,
            initialLFUCacheFractionPromil);

    // add item1 to MFU
    CloseableReference<Integer> originalRef1 = newReference(10);
    CloseableReference<Integer> valueRef1 = mCache.cache(KEYS[1], originalRef1);
    CloseableReference<Integer> valueRef1a = mCache.get(KEYS[1]);
    originalRef1.close();
    valueRef1.close();
    valueRef1a.close();

    // add item2 to MFU
    CloseableReference<Integer> originalRef2 = newReference(20);
    CloseableReference<Integer> valueRef2 = mCache.cache(KEYS[2], originalRef2);
    CloseableReference<Integer> valueRef2a = mCache.get(KEYS[2]);
    originalRef2.close();
    valueRef2.close();
    assertSharedWithCount(KEYS[2], 20, 1);
    assertSharedWithAccessCount(KEYS[2], 20, 2);
    valueRef2a.close();

    // both items are in the MFU
    assertExclusivelyOwned(KEYS[1], 10);
    assertExclusivelyOwned(KEYS[2], 20);

    // add item2 to MFU, as a result item1 should be evicted
    CloseableReference<Integer> originalRef3 = newReference(30);
    CloseableReference<Integer> valueRef3 = mCache.cache(KEYS[3], originalRef3);
    CloseableReference<Integer> valueRef3a = mCache.get(KEYS[3]);
    originalRef3.close();
    valueRef3.close();
    valueRef3a.close();
    assertExclusivelyOwned(KEYS[2], 20);
    assertExclusivelyOwned(KEYS[3], 30);
  }
Test: Add 2 frequently used elements, add a new frequently used element and make sure the cache
evicts the 1st item inserted to the cache (the least recently used one).
imagepipeline-base/src/test/java/com/facebook/imagepipeline/cache/AbstractAdaptiveCountingMemoryCacheTest.java