StatsSnapshot createSnapshot() { return new StatsSnapshot(cache.maxSize(), cache.size(), cacheHits, cacheMisses, totalDownloadSize, totalOriginalBitmapSize, totalTransformedBitmapSize, averageDownloadSize, averageOriginalBitmapSize, averageTransformedBitmapSize, downloadCount, originalBitmapCount, transformedBitmapCount, System.currentTimeMillis()); }
@Test public void evictAll() { Picasso picasso = new Picasso.Builder(RuntimeEnvironment.application).indicatorsEnabled(true).build(); picasso.cache.set("key", Bitmap.createBitmap(1, 1, ALPHA_8)); assertThat(picasso.cache.size()).isEqualTo(1); picasso.evictAll(); assertThat(picasso.cache.size()).isEqualTo(0); }
@Test public void overMaxSizeRemovesExisting() { PlatformLruCache cache = new PlatformLruCache(20); Bitmap size4 = Bitmap.createBitmap(2, 2, ALPHA_8); Bitmap size16 = Bitmap.createBitmap(4, 4, ALPHA_8); Bitmap size25 = Bitmap.createBitmap(5, 5, ALPHA_8); cache.set("small", size4); expectedPutCount++; assertHit(cache, "small", size4); cache.set("big", size16); expectedPutCount++; assertHit(cache, "small", size4); assertHit(cache, "big", size16); cache.set("big", size25); assertHit(cache, "small", size4); assertMiss(cache, "big"); assertThat(cache.size()).isEqualTo(4); }
@Test public void overMaxSizeDoesNotClear() { PlatformLruCache cache = new PlatformLruCache(16); Bitmap size4 = Bitmap.createBitmap(2, 2, ALPHA_8); Bitmap size16 = Bitmap.createBitmap(4, 4, ALPHA_8); Bitmap size25 = Bitmap.createBitmap(5, 5, ALPHA_8); cache.set("4", size4); expectedPutCount++; assertHit(cache, "4", size4); cache.set("16", size16); expectedPutCount++; expectedEvictionCount++; // size4 was evicted. assertMiss(cache, "4"); assertHit(cache, "16", size16); cache.set("25", size25); assertHit(cache, "16", size16); assertMiss(cache, "25"); assertThat(cache.size()).isEqualTo(16); }
@Test public void performCompleteWithNoStoreMemoryPolicy() { Request data = new Request.Builder(URI_1).memoryPolicy(MemoryPolicy.NO_STORE).build(); Action action = noopAction(data); BitmapHunter hunter = new BitmapHunter(mockPicasso(), dispatcher, cache, stats, action, EMPTY_REQUEST_HANDLER); hunter.result = new RequestHandler.Result(bitmap1, MEMORY); dispatcher.performComplete(hunter); assertThat(dispatcher.hunterMap).isEmpty(); assertThat(cache.size()).isEqualTo(0); }