diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-02-11 13:32:04 -0800 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-02-11 15:54:28 -0800 |
commit | 56b6ad3e28f9f86fb3186c96ddd8754e190afdf0 (patch) | |
tree | 30582f159c6d5c350daeb72434ffa7799acc6735 /core/tests | |
parent | b3103093a449ba5504b255a584f4fe9968cfda71 (diff) | |
download | frameworks_base-56b6ad3e28f9f86fb3186c96ddd8754e190afdf0.zip frameworks_base-56b6ad3e28f9f86fb3186c96ddd8754e190afdf0.tar.gz frameworks_base-56b6ad3e28f9f86fb3186c96ddd8754e190afdf0.tar.bz2 |
Add a new method, LruCache.remove
Change-Id: Iae78a2ed4d719d4f14a4677ecb6fe5bc823bb660
http://b/3184897
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/coretests/src/android/util/LruCacheTest.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/core/tests/coretests/src/android/util/LruCacheTest.java b/core/tests/coretests/src/android/util/LruCacheTest.java index 506315d..cf252e6 100644 --- a/core/tests/coretests/src/android/util/LruCacheTest.java +++ b/core/tests/coretests/src/android/util/LruCacheTest.java @@ -337,6 +337,45 @@ public final class LruCacheTest extends TestCase { assertSnapshot(cache); } + public void testRemoveDoesNotCallEntryEvicted() { + LruCache<String, String> cache = new LruCache<String, String>(10) { + @Override protected void entryEvicted(String key, String value) { + fail(); + } + }; + cache.put("a", "A"); + assertEquals("A", cache.remove("a")); + } + + public void testRemoveWithCustomSizes() { + LruCache<String, String> cache = new LruCache<String, String>(10) { + @Override protected int sizeOf(String key, String value) { + return value.length(); + } + }; + cache.put("a", "123456"); + cache.put("b", "1234"); + cache.remove("a"); + assertEquals(4, cache.size()); + } + + public void testRemoveAbsentElement() { + LruCache<String, String> cache = new LruCache<String, String>(10); + cache.put("a", "A"); + cache.put("b", "B"); + assertEquals(null, cache.remove("c")); + assertEquals(2, cache.size()); + } + + public void testRemoveNullThrows() { + LruCache<String, String> cache = new LruCache<String, String>(10); + try { + cache.remove(null); + fail(); + } catch (NullPointerException expected) { + } + } + private LruCache<String, String> newCreatingCache() { return new LruCache<String, String>(3) { @Override protected String create(String key) { |