Skip to content

Commit

Permalink
Increase the number of items used in LruCacheTest.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 302976944
  • Loading branch information
sjudd authored and glide-copybara-robot committed Mar 25, 2020
1 parent efe8023 commit 5e2ccc6
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@

@RunWith(JUnit4.class)
public class LruCacheTest {
// 1MB
private static final int SIZE = 2;
private static final int SIZE = 10;
private LruCache<String, Object> cache;
private CacheListener listener;
private String currentKey;
Expand Down Expand Up @@ -127,8 +126,9 @@ public void testItIsSizeLimited() {
public void testLeastRecentlyAddKeyEvictedFirstIfGetsAreEqual() {
Object first = new Object();
cache.put(getKey(), first);
cache.put(getKey(), new Object());
cache.put(getKey(), new Object());
for (int i = 0; i < SIZE; i++) {
cache.put(getKey(), new Object());
}

verify(listener).onItemRemoved(eq(first));
verify(listener, times(1)).onItemRemoved(any(Object.class));
Expand All @@ -145,7 +145,9 @@ public void testLeastRecentlyUsedKeyEvictedFirst() {
cache.put(leastRecentlyUsedKey, leastRecentlyUsedObject);

cache.get(mostRecentlyUsedKey);
cache.put(getKey(), new Object());
for (int i = 0; i < SIZE - 1; i++) {
cache.put(getKey(), new Object());
}

verify(listener).onItemRemoved(eq(leastRecentlyUsedObject));
verify(listener, times(1)).onItemRemoved(any(Object.class));
Expand Down Expand Up @@ -242,9 +244,11 @@ public void testCanDecreaseSizeDynamically() {
}
verify(listener, never()).onItemRemoved(any());

cache.setSizeMultiplier(0.5f);
float smallerMultiplier = 0.4f;

verify(listener).onItemRemoved(any());
cache.setSizeMultiplier(smallerMultiplier);

verify(listener, times((int) (SIZE * (1 - smallerMultiplier)))).onItemRemoved(any());
}

@Test
Expand All @@ -257,7 +261,7 @@ public void testCanResetSizeDynamically() {

cache.setSizeMultiplier(1);

verify(listener, times(sizeMultiplier)).onItemRemoved(any());
verify(listener, times((sizeMultiplier * SIZE) - SIZE)).onItemRemoved(any());
}

@Test(expected = IllegalArgumentException.class)
Expand Down

0 comments on commit 5e2ccc6

Please sign in to comment.