@Test
  public void testTrimmingMFU() {
    // 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);

    MemoryTrimType memoryTrimType = MemoryTrimType.OnCloseToDalvikHeapLimit;
    mParams = new MemoryCacheParams(2200, 16, 2200, 16, 110, PARAMS_CHECK_INTERVAL_MS);
    when(mParamsSupplier.get()).thenReturn(mParams);
    mockedSystemClock.when(() -> SystemClock.uptimeMillis()).thenReturn(PARAMS_CHECK_INTERVAL_MS);
    InOrder inOrder = inOrder(mReleaser);

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

    // insert item2 to LFU
    CloseableReference<Integer> originalRef2 = newReference(20);
    CloseableReference<Integer> cachedRef2 = mCache.cache(KEYS[2], originalRef2);
    originalRef2.close();
    cachedRef2.close();

    // Trim 50% of the cache size
    when(mCacheTrimStrategy.getTrimRatio(memoryTrimType)).thenReturn(0.5);
    mCache.trim(memoryTrimType);
    assertExclusivelyOwnedSize(1, 10);
    assertMFUExclusivelyOwned(KEYS[1], 10);

    // insert item3 to LFU
    CloseableReference<Integer> originalRef3 = newReference(30);
    CloseableReference<Integer> cachedRef3 = mCache.cache(KEYS[3], originalRef3);
    originalRef3.close();
    cachedRef3.close();

    // insert item2 to MFU
    CloseableReference<Integer> originalRef4 = newReference(40);
    CloseableReference<Integer> cachedRef4 = mCache.cache(KEYS[4], originalRef4);
    CloseableReference<Integer> cachedRef4a = mCache.get(KEYS[4]);
    originalRef4.close();
    cachedRef4.close();
    cachedRef4a.close();

    assertExclusivelyOwnedSize(3, 80);
    // Trim 50% of the cache size, this will remove item3 from LFU and item1 from MFU
    when(mCacheTrimStrategy.getTrimRatio(memoryTrimType)).thenReturn(0.5);
    mCache.trim(memoryTrimType);
    assertNotCached(KEYS[1], 10);
    assertNotCached(KEYS[3], 30);
    assertMFUExclusivelyOwned(KEYS[4], 40);
  }
test: pass illegal adaptive rate and illegal initial LFU cache fraction. expected result: fall
back and use the default adaptive rate and initial LFU fraction values.
imagepipeline-base/src/test/java/com/facebook/imagepipeline/cache/AbstractAdaptiveCountingMemoryCacheTest.java