use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalContentUriThumbnailFetchProducerTest method mockThumbnailFile.
private void mockThumbnailFile() throws Exception {
PowerMockito.whenNew(File.class).withArguments(THUMBNAIL_FILE_NAME).thenReturn(mThumbnailFile);
when(mThumbnailFile.exists()).thenReturn(true);
when(mThumbnailFile.length()).thenReturn(THUMBNAIL_FILE_SIZE);
PowerMockito.whenNew(FileInputStream.class).withArguments(THUMBNAIL_FILE_NAME).thenReturn(mock(FileInputStream.class));
EncodedImage encodedImage = mock(EncodedImage.class);
when(encodedImage.getSize()).thenReturn((int) THUMBNAIL_FILE_SIZE);
PowerMockito.whenNew(EncodedImage.class).withAnyArguments().thenReturn(encodedImage);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalExifThumbnailProducerTest method setUp.
@Before
public void setUp() throws IOException {
MockitoAnnotations.initMocks(this);
PowerMockito.mockStatic(JfifUtil.class, BitmapUtil.class);
mTestExecutorService = new TestExecutorService(new FakeClock());
mTestLocalExifThumbnailProducer = new TestLocalExifThumbnailProducer(mTestExecutorService, mPooledByteBufferFactory, mContentResolver);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
when(mImageRequest.getSourceUri()).thenReturn(mUri);
when(mProducerContext.getListener()).thenReturn(mProducerListener);
mThumbnailBytes = new byte[100];
when(mExifInterface.hasThumbnail()).thenReturn(true);
when(mExifInterface.getThumbnail()).thenReturn(mThumbnailBytes);
when(mPooledByteBufferFactory.newByteBuffer(mThumbnailBytes)).thenReturn(mThumbnailByteBuffer);
when(mExifInterface.getAttribute(ExifInterface.TAG_ORIENTATION)).thenReturn(Integer.toString(ORIENTATION));
when(JfifUtil.getAutoRotateAngleFromOrientation(ORIENTATION)).thenReturn(ANGLE);
when(BitmapUtil.decodeDimensions(any(InputStream.class))).thenReturn(new Pair(WIDTH, HEIGHT));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mCapturedEncodedImage = EncodedImage.cloneOrNull((EncodedImage) invocation.getArguments()[0]);
return null;
}
}).when(mConsumer).onNewResult(notNull(EncodedImage.class), anyBoolean());
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class LocalFileFetchProducerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
mExecutor = new TestExecutorService(new FakeClock());
mLocalFileFetchProducer = new LocalFileFetchProducer(mExecutor, mPooledByteBufferFactory);
mFile = new File(RuntimeEnvironment.application.getExternalFilesDir(null), TEST_FILENAME);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(mFile));
bos.write(new byte[INPUT_STREAM_LENGTH], 0, INPUT_STREAM_LENGTH);
bos.close();
mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
when(mImageRequest.getSourceFile()).thenReturn(mFile);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mCapturedEncodedImage = EncodedImage.cloneOrNull((EncodedImage) invocation.getArguments()[0]);
return null;
}
}).when(mConsumer).onNewResult(notNull(EncodedImage.class), anyBoolean());
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class ArtDecoderTest method setUp.
@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);
ByteBuffer buf = mArtDecoder.mDecodeBuffers.acquire();
mTempStorage = buf.array();
mArtDecoder.mDecodeBuffers.release(buf);
}
use of com.facebook.imagepipeline.image.EncodedImage in project fresco by facebook.
the class GingerbreadPurgeableDecoderTest method setUp.
@Before
public void setUp() {
mBitmap = MockBitmapFactory.create();
mBitmapCounter = new BitmapCounter(MAX_BITMAP_COUNT, MAX_BITMAP_SIZE);
mockStatic(BitmapCounterProvider.class);
when(BitmapCounterProvider.get()).thenReturn(mBitmapCounter);
mockStatic(BitmapFactory.class);
when(BitmapFactory.decodeFileDescriptor(any(FileDescriptor.class), any(Rect.class), any(BitmapFactory.Options.class))).thenReturn(mBitmap);
mInputBuf = new byte[LENGTH];
PooledByteBuffer input = new TrivialPooledByteBuffer(mInputBuf, POINTER);
mByteBufferRef = CloseableReference.of(input);
mEncodedImage = new EncodedImage(mByteBufferRef);
mDecodeBuf = new byte[LENGTH + 2];
mDecodeBufRef = CloseableReference.of(mDecodeBuf, mock(ResourceReleaser.class));
mockStatic(Bitmaps.class);
mGingerbreadPurgeableDecoder = new GingerbreadPurgeableDecoder();
}
Aggregations