Search in sources :

Example 1 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService in project fresco by facebook.

the class AnimatedDrawableCachingBackendImplTest method setup.

@Before
public void setup() {
    mActivityManager = (ActivityManager) RuntimeEnvironment.application.getSystemService(Context.ACTIVITY_SERVICE);
    mFakeClock = new FakeClock();
    mExecutorService = new TestExecutorService(mFakeClock);
    mAnimatedDrawableUtil = new AnimatedDrawableUtil();
    mDrawableBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
}
Also used : TestAnimatedDrawableBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) AnimatedDrawableUtil(com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil) Before(org.junit.Before)

Example 2 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService in project fresco by facebook.

the class AnimatedSingleUsePostprocessorProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mTestExecutorService = new TestExecutorService(new FakeClock());
    mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
    when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
    when(mProducerContext.getId()).thenReturn(mRequestId);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    mResults = new ArrayList<>();
    when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
    when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mResults.add(((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
            return null;
        }
    }).when(mConsumer).onNewResult(any(CloseableReference.class), anyBoolean());
    mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
    mSourceBitmap = mock(Bitmap.class);
    mSourceCloseableStaticBitmap = mock(CloseableStaticBitmap.class);
    when(mSourceCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mSourceBitmap);
    mSourceCloseableImageRef = CloseableReference.<CloseableImage>of(mSourceCloseableStaticBitmap);
    mDestinationBitmap = mock(Bitmap.class);
    mDestinationCloseableBitmapRef = CloseableReference.of(mDestinationBitmap, mBitmapResourceReleaser);
}
Also used : CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) Bitmap(android.graphics.Bitmap) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) CloseableReference(com.facebook.common.references.CloseableReference) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap)

Example 3 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService in project fresco by facebook.

the class BufferedDiskCacheTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mCloseableReference = CloseableReference.of(mPooledByteBuffer);
    mEncodedImage = new EncodedImage(mCloseableReference);
    List<CacheKey> keys = new ArrayList<>();
    keys.add(new SimpleCacheKey("http://test.uri"));
    keys.add(new SimpleCacheKey("http://tyrone.uri"));
    keys.add(new SimpleCacheKey("http://ian.uri"));
    mCacheKey = new MultiCacheKey(keys);
    mIsCancelled = new AtomicBoolean(false);
    FakeClock fakeClock = new FakeClock();
    mReadPriorityExecutor = new TestExecutorService(fakeClock);
    mWritePriorityExecutor = new TestExecutorService(fakeClock);
    when(mBinaryResource.openStream()).thenReturn(mInputStream);
    when(mBinaryResource.size()).thenReturn(123L);
    when(mByteBufferFactory.newByteBuffer(same(mInputStream), eq(123))).thenReturn(mPooledByteBuffer);
    mockStatic(StagingArea.class);
    when(StagingArea.getInstance()).thenReturn(mStagingArea);
    mBufferedDiskCache = new BufferedDiskCache(mFileCache, mByteBufferFactory, mPooledByteStreams, mReadPriorityExecutor, mWritePriorityExecutor, mImageCacheStatsTracker);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FakeClock(com.facebook.imagepipeline.testing.FakeClock) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) ArrayList(java.util.ArrayList) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) CacheKey(com.facebook.cache.common.CacheKey) MultiCacheKey(com.facebook.cache.common.MultiCacheKey) SimpleCacheKey(com.facebook.cache.common.SimpleCacheKey) Before(org.junit.Before)

Example 4 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService 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());
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) InputStream(java.io.InputStream) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) Pair(android.util.Pair)

Example 5 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService 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());
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

FakeClock (com.facebook.imagepipeline.testing.FakeClock)17 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)17 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6 CloseableReference (com.facebook.common.references.CloseableReference)4 Before (org.junit.Before)4 File (java.io.File)3 Bitmap (android.graphics.Bitmap)2 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)2 TestScheduledExecutorService (com.facebook.imagepipeline.testing.TestScheduledExecutorService)2 InputStream (java.io.InputStream)2 Pair (android.util.Pair)1 CacheEventListener (com.facebook.cache.common.CacheEventListener)1 CacheKey (com.facebook.cache.common.CacheKey)1 MultiCacheKey (com.facebook.cache.common.MultiCacheKey)1 SimpleCacheKey (com.facebook.cache.common.SimpleCacheKey)1 DiskTrimmableRegistry (com.facebook.common.disk.DiskTrimmableRegistry)1 UiThreadImmediateExecutorService (com.facebook.common.executors.UiThreadImmediateExecutorService)1 SystemClock (com.facebook.common.time.SystemClock)1 TestAnimatedDrawableBackend (com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend)1 AnimatedDrawableUtil (com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil)1