コード例 #1
0
 @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);
 }
コード例 #2
0
 @Test
 public void testLocalVideoMiniThumbnailSuccess() throws Exception {
   when(mImageRequest.getPreferredWidth()).thenReturn(100);
   when(mImageRequest.getPreferredHeight()).thenReturn(100);
   when(android.media.ThumbnailUtils.createVideoThumbnail(
           mFile.getPath(), MediaStore.Images.Thumbnails.MINI_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);
   verify(mProducerListener).onProducerFinishWithSuccess(mRequestId, PRODUCER_NAME, null);
 }
コード例 #3
0
 @Test(expected = RuntimeException.class)
 public void testFetchLocalFileFailsByThrowing() throws Exception {
   when(android.media.ThumbnailUtils.createVideoThumbnail(
           mFile.getPath(), MediaStore.Images.Thumbnails.MICRO_KIND))
       .thenThrow(mException);
   verify(mConsumer).onFailure(mException);
   verify(mProducerListener).onProducerStart(mRequestId, PRODUCER_NAME);
   verify(mProducerListener)
       .onProducerFinishWithFailure(mRequestId, PRODUCER_NAME, mException, null);
 }
コード例 #4
0
 @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);
 }