@Test public void decodeFrame_withTargetSizeOriginalWidthOnly_onApi27_doesNotThrow() throws IOException { Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.getFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)) .thenReturn(expected); verify(retriever, never()).getScaledFrameAtTime(anyLong(), anyInt(), anyInt(), anyInt()); assertThat(decoder.decode(resource, Target.SIZE_ORIGINAL, 100, options).get()) .isSameAs(expected); }
@Test public void decodeFrame_withTargetSizeOriginal_onApi27_doesNotThrow() throws IOException { Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.getFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)) .thenReturn(expected); verify(retriever, never()).getScaledFrameAtTime(anyLong(), anyInt(), anyInt(), anyInt()); assertThat(decoder.decode(resource, Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL, options).get()) .isSameAs(expected); }
@Test public void decodeFrame_withTargetSizeOriginalHeightOnly_onApi27_doesNotThrow() throws IOException { Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.getFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)) .thenReturn(expected); verify(retriever, never()).getScaledFrameAtTime(anyLong(), anyInt(), anyInt(), anyInt()); assertThat(decoder.decode(resource, 100, Target.SIZE_ORIGINAL, options).get()) .isSameAs(expected); } }
@Test public void testReleasesMediaMetadataRetriever() throws IOException { Util.setSdkVersionInt(19); decoder.decode(resource, 1, 2, options); verify(retriever).release(); }
@Test public void getScaledFrameAtTime() throws IOException { // Anything other than NONE. options.set(DownsampleStrategy.OPTION, DownsampleStrategy.AT_LEAST); Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)) .thenReturn("100"); when(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)) .thenReturn("100"); when(retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION)) .thenReturn("0"); when(retriever.getScaledFrameAtTime(-1, MediaMetadataRetriever.OPTION_CLOSEST_SYNC, 100, 100)) .thenReturn(expected); assertThat(decoder.decode(resource, 100, 100, options).get()).isSameAs(expected); }
@Test public void testReturnsRetrievedFrameForResource() throws IOException { Util.setSdkVersionInt(19); Bitmap expected = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); when(retriever.getFrameAtTime(VideoDecoder.DEFAULT_FRAME, VideoDecoder.DEFAULT_FRAME_OPTION)) .thenReturn(expected); Resource<Bitmap> result = Preconditions.checkNotNull(decoder.decode(resource, 100, 100, options)); verify(initializer).initialize(retriever, resource); assertEquals(expected, result.get()); }
@Test public void testDoesNotSpecifyThumbnailFrameIfCalledWithoutFrameNumber() throws IOException { Util.setSdkVersionInt(19); decoder = new VideoDecoder<>(bitmapPool, initializer, factory); decoder.decode(resource, 100, 100, options); verify(retriever).getFrameAtTime(VideoDecoder.DEFAULT_FRAME, VideoDecoder.DEFAULT_FRAME_OPTION); }
@Test public void testSpecifiesThumbnailFrameIfICalledWithFrameNumber() throws IOException { Util.setSdkVersionInt(19); long frame = 5; options.set(VideoDecoder.TARGET_FRAME, frame); decoder = new VideoDecoder<>(bitmapPool, initializer, factory); decoder.decode(resource, 100, 100, options); verify(retriever).getFrameAtTime(frame, VideoDecoder.DEFAULT_FRAME_OPTION); }
@Test(expected = IllegalArgumentException.class) public void testThrowsExceptionIfCalledWithInvalidFrame() throws IOException { Util.setSdkVersionInt(19); options.set(VideoDecoder.TARGET_FRAME, -5L); new VideoDecoder<>(bitmapPool, initializer, factory).decode(resource, 100, 100, options); }