@Test public void testPrefetchToBitmapCache() { Producer<Void> prefetchProducerSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImagePrefetchProducerSequence(mImageRequest)) .thenReturn(prefetchProducerSequence); DataSource<Void> dataSource = mImagePipeline.prefetchToBitmapCache(mImageRequest, mCallerContext); assertTrue(!dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.MEDIUM); }
@Test public void testFetchDecodedImage() { Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = mImagePipeline.fetchDecodedImage(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
@Test public void testFetchDecodedImageWithRequestLevel() { Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = mImagePipeline.fetchDecodedImage( mImageRequest, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.DISK_CACHE); }
@Test public void testFetchFromBitmapCacheDueToMethodCall() { Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); mImagePipeline.fetchImageFromBitmapCache(mImageRequest, mCallerContext); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); }
@Test public void testFetchFromBitmapCacheDueToImageRequest() { Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mImageRequest.getLowestPermittedRequestLevel()) .thenReturn(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); mImagePipeline.fetchDecodedImage(mImageRequest, mCallerContext); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); assertEquals( producerContextArgumentCaptor.getValue().getLowestPermittedRequestLevel(), ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); }
@Test public void testGetBitmapCacheGetSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline.getDataSourceSupplier( mImageRequest, mCallerContext, ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE); Producer<CloseableReference<CloseableImage>> bitmapCacheSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(bitmapCacheSequence); dataSourceSupplier.get(); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(bitmapCacheSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
@Test public void testGetFullFetchSupplier() { Supplier<DataSource<CloseableReference<CloseableImage>>> dataSourceSupplier = mImagePipeline .getDataSourceSupplier(mImageRequest, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH); Producer<CloseableReference<CloseableImage>> decodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getDecodedImageProducerSequence(mImageRequest)) .thenReturn(decodedSequence); DataSource<CloseableReference<CloseableImage>> dataSource = dataSourceSupplier.get(); assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", false); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", false); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(decodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
private void verifyPrefetchToDiskCache( DataSource<Void> dataSource, Producer<Void> prefetchProducerSequence, Priority priority) { assertFalse(dataSource.isFinished()); verify(mRequestListener1).onRequestStart(mImageRequest, mCallerContext, "0", true); verify(mRequestListener2).onRequestStart(mImageRequest, mCallerContext, "0", true); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(prefetchProducerSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertFalse(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(priority, producerContextArgumentCaptor.getValue().getPriority()); }
@Test public void testFetchLocalEncodedImage() { Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)) .thenReturn(encodedSequence); when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("file:///local/file")); DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class); verify(mRequestListener1).onRequestStart( argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false)); ImageRequest capturedImageRequest = argumentCaptor.getValue(); assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri()); verify(mRequestListener2).onRequestStart( argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false)); capturedImageRequest = argumentCaptor.getValue(); assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri()); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(encodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
@Test public void testFetchNetworkEncodedImage() { Producer<CloseableReference<PooledByteBuffer>> encodedSequence = mock(Producer.class); when(mProducerSequenceFactory.getEncodedImageProducerSequence(mImageRequest)) .thenReturn(encodedSequence); when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("http://test")); DataSource<CloseableReference<PooledByteBuffer>> dataSource = mImagePipeline.fetchEncodedImage(mImageRequest, mCallerContext); assertFalse(dataSource.isFinished()); ArgumentCaptor<ImageRequest> argumentCaptor = ArgumentCaptor.forClass(ImageRequest.class); verify(mRequestListener1).onRequestStart( argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false)); ImageRequest capturedImageRequest = argumentCaptor.getValue(); assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri()); verify(mRequestListener2).onRequestStart( argumentCaptor.capture(), eq(mCallerContext), eq("0"), eq(false)); capturedImageRequest = argumentCaptor.getValue(); assertSame(mImageRequest.getSourceUri(), capturedImageRequest.getSourceUri()); ArgumentCaptor<ProducerContext> producerContextArgumentCaptor = ArgumentCaptor.forClass(ProducerContext.class); verify(encodedSequence) .produceResults(any(Consumer.class), producerContextArgumentCaptor.capture()); assertTrue(producerContextArgumentCaptor.getValue().isIntermediateResultExpected()); assertEquals(producerContextArgumentCaptor.getValue().getPriority(), Priority.HIGH); }
public OkHttpNetworkFetchState( Consumer<EncodedImage> consumer, ProducerContext producerContext) { super(consumer, producerContext); }
@Override public OkHttpNetworkFetchState createFetchState( Consumer<EncodedImage> consumer, ProducerContext context) { return new OkHttpNetworkFetchState(consumer, context); }
public VolleyNetworkFetchState( Consumer<EncodedImage> consumer, ProducerContext producerContext) { super(consumer, producerContext); }
@Override public VolleyNetworkFetchState createFetchState( Consumer<EncodedImage> consumer, ProducerContext context) { return new VolleyNetworkFetchState(consumer, context); }