@Test
  public void testEviction_ByTotalSize() {
    mCache =
        createDummyAdaptiveCountingMemoryCache(
            mParamsSupplier,
            mCacheTrimStrategy,
            mValueDescriptor,
            100,
            1,
            2,
            initialLFUCacheFractionPromil);
    // value 4 cannot fit the cache
    CloseableReference<Integer> originalRef1 = newReference(400);
    CloseableReference<Integer> valueRef1 = mCache.cache(KEYS[1], originalRef1);
    originalRef1.close();
    CloseableReference<Integer> originalRef2 = newReference(500);
    CloseableReference<Integer> valueRef2 = mCache.cache(KEYS[2], originalRef2);
    originalRef2.close();
    CloseableReference<Integer> originalRef3 = newReference(100);
    CloseableReference<Integer> valueRef3 = mCache.cache(KEYS[3], originalRef3);
    originalRef3.close();
    CloseableReference<Integer> originalRef4 = newReference(1000);
    CloseableReference<Integer> valueRef4 = mCache.cache(KEYS[4], originalRef4);
    originalRef4.close();
    assertTotalSize(3, 1000);
    assertExclusivelyOwnedSize(0, 0);
    assertSharedWithCount(KEYS[1], 400, 1);
    assertSharedWithCount(KEYS[2], 500, 1);
    assertSharedWithCount(KEYS[3], 100, 1);
    assertNotCached(KEYS[4], 1000);
    assertNull(valueRef4);

    // closing the clients of cached items will make them viable for eviction
    valueRef1.close();
    valueRef2.close();
    valueRef3.close();
    assertTotalSize(1, 100);
    assertExclusivelyOwnedSize(1, 100);

    // value 4 can now fit after evicting value1 and value2
    valueRef4 = mCache.cache(KEYS[4], newReference(1000));
    assertTotalSize(2, 1100);
    assertExclusivelyOwnedSize(1, 100);
    assertNotCached(KEYS[1], 400);
    assertNotCached(KEYS[2], 500);
    assertSharedWithCount(KEYS[4], 1000, 1);
    verify(mReleaser).release(400);
    verify(mReleaser).release(500);
    valueRef4.close();
  }
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