BitmapLruCache extends LruCacheAdapter<String, Bitmap> { @Override public boolean has(String key) { if (key == null) return false; Bitmap value = get(key); return (value != null && !value.isRecycled()); } BitmapLruCache(float percentOfAvailableMemory);  BitmapLruCache(int maxSize); @Override boolean has(String key);  }
@Test public void testSimpleAdd() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); cache.put("asd", Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)); Assert.assertTrue(cache.has("asd")); }
@Test public void testSimpleOnNullKey() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); Assert.assertFalse(cache.has(null)); }
@Test public void testCacheIsEmpty() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); Assert.assertFalse(cache.has("asd")); Assert.assertEquals(0, cache.getCurrentSize()); }
@Test public void testCacheDeletes() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); cache.put("asd", Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)); Assert.assertTrue(cache.has("asd")); cache.remove("asd"); Assert.assertFalse(cache.has("asd")); }
@Test public void testClear() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); cache.put("asd", Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)); Assert.assertTrue(cache.has("asd")); cache.clear(); Assert.assertFalse(cache.has("asd")); }
@Test public void testGet() { BitmapLruCache cache = new BitmapLruCache(DEFAULT_SIZE); cache.put("asd", Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888)); Assert.assertTrue(cache.has("asd")); Assert.assertNotNull(cache.get("asd")); }