private Map<String, String> getExtraMap(
     @Nullable CloseableImage image, long queueTime, QualityInfo quality, boolean isFinal) {
   if (!mProducerListener.requiresExtraMap(mProducerContext.getId())) {
     return null;
   }
   String queueStr = String.valueOf(queueTime);
   String qualityStr = String.valueOf(quality.isOfGoodEnoughQuality());
   String finalStr = String.valueOf(isFinal);
   String imageTypeStr = String.valueOf(mProducerContext.getImageRequest().getImageType());
   if (image instanceof CloseableStaticBitmap) {
     Bitmap bitmap = ((CloseableStaticBitmap) image).getUnderlyingBitmap();
     String sizeStr = bitmap.getWidth() + "x" + bitmap.getHeight();
     return ImmutableMap.of(
         BITMAP_SIZE_KEY,
         sizeStr,
         JobScheduler.QUEUE_TIME_KEY,
         queueStr,
         HAS_GOOD_QUALITY_KEY,
         qualityStr,
         IS_FINAL_KEY,
         finalStr,
         IMAGE_TYPE_KEY,
         imageTypeStr);
   } else {
     return ImmutableMap.of(
         JobScheduler.QUEUE_TIME_KEY,
         queueStr,
         HAS_GOOD_QUALITY_KEY,
         qualityStr,
         IS_FINAL_KEY,
         finalStr,
         IMAGE_TYPE_KEY,
         imageTypeStr);
   }
 }
 private Map<String, String> getExtraMap(
     ProducerListener listener, String requestId, Postprocessor postprocessor) {
   if (!listener.requiresExtraMap(requestId)) {
     return null;
   }
   return ImmutableMap.of(POSTPROCESSOR, postprocessor.getName());
 }
 @Test
 public void testLocalVideoMicroThumbnailSuccess() throws Exception {
   when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
   when(android.media.ThumbnailUtils.createVideoThumbnail(
           mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND))
       .thenReturn(mBitmap);
   doAnswer(
           new Answer() {
             @Override
             public Object answer(InvocationOnMock invocation) throws Throwable {
               mCloseableReference = ((CloseableReference) invocation.getArguments()[0]).clone();
               return null;
             }
           })
       .when(mConsumer)
       .onNewResult(any(CloseableReference.class), eq(true));
   mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext);
   mExecutor.runUntilIdle();
   assertEquals(1, mCloseableReference.getUnderlyingReferenceTestOnly().getRefCountTestOnly());
   assertEquals(
       mBitmap, mCloseableReference.getUnderlyingReferenceTestOnly().get().getUnderlyingBitmap());
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> thumbnailFoundMap =
       ImmutableMap.of(LocalVideoThumbnailProducer.CREATED_THUMBNAIL, "true");
   verify(mProducerListener)
       .onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, thumbnailFoundMap);
 }
 @Test
 public void testEncodedMemoryCacheGetNotFoundNextProducerFailure() {
   setupEncodedMemoryCacheGetNotFound();
   setupNextProducerFailure();
   mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
   verify(mConsumer).onFailure(mException);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.VALUE_FOUND, "false");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
 }
 @Test
 public void testBitmapMemoryCacheGetNotFoundInputProducerSuccess() {
   setupBitmapCacheGetNotFound();
   setupInputProducerStreamingSuccess();
   mBitmapMemoryCacheGetProducer.produceResults(mConsumer, mProducerContext);
   verify(mConsumer).onNewResult(mFinalImageReference, true);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap =
       ImmutableMap.of(BitmapMemoryCacheProducer.EXTRA_CACHED_VALUE_FOUND, "false");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
 }
 @Test
 public void testEncodedMemoryCacheGetNotFoundLowestLevelReached() {
   setupEncodedMemoryCacheGetNotFound();
   when(mProducerContext.getLowestPermittedRequestLevel())
       .thenReturn(ImageRequest.RequestLevel.ENCODED_MEMORY_CACHE);
   mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
   verify(mConsumer).onNewResult(null, true);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.VALUE_FOUND, "false");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
   verifyNoMoreInteractions(mNextProducer);
 }
 @Test
 public void testBitmapMemoryCacheGetSuccessful() {
   setupBitmapCacheGetSuccess();
   when(mProducerContext.getLowestPermittedRequestLevel())
       .thenReturn(ImageRequest.RequestLevel.BITMAP_MEMORY_CACHE);
   mBitmapMemoryCacheGetProducer.produceResults(mConsumer, mProducerContext);
   verify(mConsumer).onNewResult(mFinalImageReference, true);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap =
       ImmutableMap.of(BitmapMemoryCacheProducer.EXTRA_CACHED_VALUE_FOUND, "true");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
   Assert.assertTrue(!mFinalImageReference.isValid());
 }
 private Map<String, String> getExtraMap(
     final long queueTime, final QualityInfo qualityInfo, final boolean isFinal) {
   if (!mProducerListener.requiresExtraMap(mProducerContext.getId())) {
     return null;
   }
   return ImmutableMap.of(
       QUEUE_TIME_KEY,
       String.valueOf(queueTime),
       HAS_GOOD_QUALITY_KEY,
       String.valueOf(qualityInfo.isOfGoodEnoughQuality()),
       IS_FINAL_KEY,
       String.valueOf(isFinal));
 }
 @Test
 public void testLocalVideoMicroThumbnailReturnsNull() throws Exception {
   when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
   when(android.media.ThumbnailUtils.createVideoThumbnail(
           mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND))
       .thenReturn(null);
   mLocalVideoThumbnailProducer.produceResults(mConsumer, mProducerContext);
   mExecutor.runUntilIdle();
   verify(mConsumer).onNewResult(null, true);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> thumbnailNotFoundMap =
       ImmutableMap.of(LocalVideoThumbnailProducer.CREATED_THUMBNAIL, "false");
   verify(mProducerListener)
       .onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, thumbnailNotFoundMap);
 }
 @Test
 public void testEncodedMemoryCacheGetSuccessful() {
   setupEncodedMemoryCacheGetSuccess();
   when(mProducerContext.getLowestPermittedRequestLevel())
       .thenReturn(ImageRequest.RequestLevel.ENCODED_MEMORY_CACHE);
   mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
   ArgumentCaptor<EncodedImage> argumentCaptor = ArgumentCaptor.forClass(EncodedImage.class);
   verify(mConsumer).onNewResult(argumentCaptor.capture(), eq(true));
   EncodedImage encodedImage = argumentCaptor.getValue();
   Assert.assertSame(
       mFinalEncodedImage.getUnderlyingReferenceTestOnly(),
       encodedImage.getUnderlyingReferenceTestOnly());
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.VALUE_FOUND, "true");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
   Assert.assertFalse(mFinalImageReference.isValid());
 }
 @Test
 public void testEncodedMemoryCacheGetNotFoundNextProducerSuccess() {
   setupEncodedMemoryCacheGetNotFound();
   setupNextProducerStreamingSuccess();
   mEncodedMemoryCacheProducer.produceResults(mConsumer, mProducerContext);
   verify(mMemoryCache, never()).cache(mCacheKey, mIntermediateImageReference);
   ArgumentCaptor<CloseableReference> argumentCaptor =
       ArgumentCaptor.forClass(CloseableReference.class);
   verify(mMemoryCache).cache(eq(mCacheKey), argumentCaptor.capture());
   CloseableReference<PooledByteBuffer> capturedRef =
       (CloseableReference<PooledByteBuffer>) argumentCaptor.getValue();
   Assert.assertSame(
       mFinalImageReference.getUnderlyingReferenceTestOnly(),
       capturedRef.getUnderlyingReferenceTestOnly());
   verify(mConsumer).onNewResult(mIntermediateEncodedImage, false);
   verify(mConsumer).onNewResult(mFinalEncodedImage, true);
   Assert.assertTrue(EncodedImage.isValid(mFinalEncodedImageClone));
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   Map<String, String> extraMap = ImmutableMap.of(EncodedMemoryCacheProducer.VALUE_FOUND, "false");
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, extraMap);
 }