ArtDecoderTest.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:GitHub 作者:
@Before
public void setUp() throws Exception {
  final Random random = new Random();
  random.setSeed(RANDOM_SEED);
  mEncodedBytes = new byte[ENCODED_BYTES_LENGTH];
  random.nextBytes(mEncodedBytes);

  mPooledByteBuffer = new TrivialPooledByteBuffer(mEncodedBytes);
  mBitmapPool = mock(BitmapPool.class);
  mArtDecoder = new ArtDecoder(mBitmapPool, 1, new Pools.SynchronizedPool(1));

  mByteBufferRef = CloseableReference.of(mPooledByteBuffer);
  mEncodedImage = new EncodedImage(mByteBufferRef);
  mEncodedImage.setImageFormat(DefaultImageFormats.JPEG);
  mBitmap = MockBitmapFactory.create();
  doReturn(mBitmap).when(mBitmapPool).get(MockBitmapFactory.DEFAULT_BITMAP_SIZE);

  mBitmapFactoryDefaultAnswer = new Answer<Bitmap>() {
    @Override
    public Bitmap answer(InvocationOnMock invocation) throws Throwable {
      final BitmapFactory.Options options = (BitmapFactory.Options) invocation.getArguments()[2];
      options.outWidth = MockBitmapFactory.DEFAULT_BITMAP_WIDTH;
      options.outHeight = MockBitmapFactory.DEFAULT_BITMAP_HEIGHT;
      verifyBitmapFactoryOptions(options);
      return options.inJustDecodeBounds ? null : mBitmap;
    }
  };
  whenBitmapFactoryDecodeStream().thenAnswer(mBitmapFactoryDefaultAnswer);

  mBitmapRegionDecoder = mock(BitmapRegionDecoder.class);
  whenBitmapRegionDecoderNewInstance().thenReturn(mBitmapRegionDecoder);

  ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire();
  mTempStorage = buf.array();
  mArtDecoder.mDecodeBuffers.release(buf);

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号