@Test public void getWithCacheMiss() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); // Ask for the image to be loaded. mImageLoader.get("http://foo", listener); // Second pass to test deduping logic. mImageLoader.get("http://foo", listener); // Response callback should be called both times. verify(listener, times(2)).onResponse(any(ImageLoader.ImageContainer.class), eq(true)); // But request should be enqueued only once. verify(mRequestQueue, times(1)).add(any(Request.class)); }
@Test public void getWithCacheMiss() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); // Ask for the image to be loaded. mImageLoader.get("http://foo", listener); // Second pass to test deduping logic. mImageLoader.get("http://foo", listener); // Response callback should be called both times. verify(listener, times(2)).onResponse(any(ImageLoader.ImageContainer.class), eq(true)); // But request should be enqueued only once. verify(mRequestQueue, times(1)).add(any(Request.class)); }
@Test public void getWithCacheHit() throws Exception { Bitmap bitmap = Bitmap.createBitmap(1, 1, null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); when(mImageCache.getBitmap(anyString())).thenReturn(bitmap); ImageLoader.ImageContainer ic = mImageLoader.get("http://foo", listener); Assert.assertSame(bitmap, ic.getBitmap()); verify(listener).onResponse(ic, true); }
@Test public void getWithCacheMiss() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); // Ask for the image to be loaded. mImageLoader.get("http://foo", listener); // Second pass to test deduping logic. mImageLoader.get("http://foo", listener); // Response callback should be called both times. verify(listener, times(2)).onResponse(any(ImageLoader.ImageContainer.class), eq(true)); // But request should be enqueued only once. verify(mRequestQueue, times(1)).add(any(Request.class)); }
@Test public void getWithCacheHit() throws Exception { Bitmap bitmap = Bitmap.createBitmap(1, 1, null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); when(mImageCache.getBitmap(anyString())).thenReturn(bitmap); ImageLoader.ImageContainer ic = mImageLoader.get("http://foo", listener); Assert.assertSame(bitmap, ic.getBitmap()); verify(listener).onResponse(ic, true); }
@Test public void getWithCacheHit() throws Exception { Bitmap bitmap = Bitmap.createBitmap(1, 1, null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); when(mImageCache.getBitmap(anyString())).thenReturn(bitmap); ImageLoader.ImageContainer ic = mImageLoader.get("http://foo", listener); Assert.assertSame(bitmap, ic.getBitmap()); verify(listener).onResponse(ic, true); }
@Test public void isCachedChecksCache() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); Assert.assertFalse(mImageLoader.isCached("http://foo", 0, 0)); }
@Test public void isCachedChecksCache() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); Assert.assertFalse(mImageLoader.isCached("http://foo", 0, 0)); }
@Test public void getWithCacheHit() throws Exception { Bitmap bitmap = Bitmap.createBitmap(1, 1, null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); when(mImageCache.getBitmap(anyString())).thenReturn(bitmap); ImageLoader.ImageContainer ic = mImageLoader.get("http://foo", listener); Assert.assertSame(bitmap, ic.getBitmap()); verify(listener).onResponse(ic, true); }
@Test public void isCachedChecksCache() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); Assert.assertFalse(mImageLoader.isCached("http://foo", 0, 0)); }
/** * Checks if the item is available in the cache. * @param requestUrl The url of the remote image * @param maxWidth The maximum width of the returned image. * @param maxHeight The maximum height of the returned image. * @return True if the item exists in cache, false otherwise. */ public boolean isCached(String requestUrl, int maxWidth, int maxHeight) { throwIfNotOnMainThread(); String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight); return mCache.getBitmap(cacheKey) != null; }
Bitmap cachedBitmap = mCache.getBitmap(cacheKey); if (cachedBitmap != null) {
Bitmap cachedBitmap = mCache.getBitmap(cacheKey); if (cachedBitmap != null) {
Bitmap cachedBitmap = mCache.getBitmap(cacheKey); if (cachedBitmap != null) {
/** * Checks if the item is available in the cache. * * @param requestUrl The url of the remote image * @param maxWidth The maximum width of the returned image. * @param maxHeight The maximum height of the returned image. * @param scaleType The scaleType of the imageView. * @return True if the item exists in cache, false otherwise. */ public boolean isCached(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType) { throwIfNotOnMainThread(); String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight, scaleType); return mCache.getBitmap(cacheKey) != null; }
/** * Checks if the item is available in the cache. * * @param requestUrl The url of the remote image * @param maxWidth The maximum width of the returned image. * @param maxHeight The maximum height of the returned image. * @param scaleType The scaleType of the imageView. * @return True if the item exists in cache, false otherwise. */ public boolean isCached(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType) { throwIfNotOnMainThread(); String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight, scaleType); return mCache.getBitmap(cacheKey) != null; }
/** * Checks if the item is available in the cache. * * @param requestUrl The url of the remote image * @param maxWidth The maximum width of the returned image. * @param maxHeight The maximum height of the returned image. * @param scaleType The scaleType of the imageView. * @return True if the item exists in cache, false otherwise. */ public boolean isCached(String requestUrl, int maxWidth, int maxHeight, ScaleType scaleType) { throwIfNotOnMainThread(); String cacheKey = getCacheKey(requestUrl, maxWidth, maxHeight, scaleType); return mCache.getBitmap(cacheKey) != null; }
@Test public void getWithCacheHit() throws Exception { Bitmap bitmap = Bitmap.createBitmap(1, 1, null); ImageLoader.ImageListener listener = mock(ImageLoader.ImageListener.class); when(mImageCache.getBitmap(anyString())).thenReturn(bitmap); ImageLoader.ImageContainer ic = mImageLoader.get("http://foo", listener); Assert.assertSame(bitmap, ic.getBitmap()); verify(listener).onResponse(ic, true); }
@Test public void isCachedChecksCache() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); Assert.assertFalse(mImageLoader.isCached("http://foo", 0, 0)); }
@Test public void isCachedChecksCache() throws Exception { when(mImageCache.getBitmap(anyString())).thenReturn(null); Assert.assertFalse(mImageLoader.isCached("http://foo", 0, 0)); }