Search in sources :

Example 16 with FakeClock

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

the class LocalResourceFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(mResources.openRawResourceFd(eq(TEST_ID))).thenReturn(mAssetFileDescriptor);
    when(mAssetFileDescriptor.getLength()).thenReturn((long) TEST_DATA_LENGTH);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalResourceFetchProducer = new LocalResourceFetchProducer(mExecutor, mPooledByteBufferFactory, mResources);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("res:///" + TEST_ID));
    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)

Example 17 with FakeClock

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

the class RepeatedPostprocessorProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mTestExecutorService = new TestExecutorService(new FakeClock());
    mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, /* isPrefetch */
    false, /* isIntermediateResultExpected */
    Priority.MEDIUM);
    when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
    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);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) CloseableReference(com.facebook.common.references.CloseableReference)

Example 18 with FakeClock

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

the class ResizeAndRotateProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mFakeClockForWorker = new FakeClock();
    mFakeClockForScheduled = new FakeClock();
    mFakeClockForWorker.incrementBy(1000);
    mFakeClockForScheduled.incrementBy(1000);
    PowerMockito.mockStatic(SystemClock.class);
    when(SystemClock.uptimeMillis()).thenAnswer(new Answer<Long>() {

        @Override
        public Long answer(InvocationOnMock invocation) throws Throwable {
            return mFakeClockForWorker.now();
        }
    });
    when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("http://testuri"));
    mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClockForScheduled);
    mUiThreadImmediateExecutorService = mock(UiThreadImmediateExecutorService.class);
    when(mUiThreadImmediateExecutorService.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class))).thenAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return mTestScheduledExecutorService.schedule((Runnable) invocation.getArguments()[0], (long) invocation.getArguments()[1], (TimeUnit) invocation.getArguments()[2]);
        }
    });
    PowerMockito.mockStatic(UiThreadImmediateExecutorService.class);
    when(UiThreadImmediateExecutorService.getInstance()).thenReturn(mUiThreadImmediateExecutorService);
    PowerMockito.mockStatic(JpegTranscoder.class);
    PowerMockito.when(JpegTranscoder.isRotationAngleAllowed(anyInt())).thenCallRealMethod();
    mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(anyString())).thenReturn(true);
    mIntermediateResult = CloseableReference.of(mock(PooledByteBuffer.class));
    mFinalResult = CloseableReference.of(mock(PooledByteBuffer.class));
    mResizeAndRotateProducerConsumer = null;
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mResizeAndRotateProducerConsumer = (Consumer<EncodedImage>) invocation.getArguments()[0];
            return null;
        }
    }).when(mInputProducer).produceResults(any(Consumer.class), any(ProducerContext.class));
    doReturn(mPooledByteBufferOutputStream).when(mPooledByteBufferFactory).newOutputStream();
    mPooledByteBuffer = new TrivialPooledByteBuffer(new byte[] { 1 }, 0);
    doReturn(mPooledByteBuffer).when(mPooledByteBufferOutputStream).toByteBuffer();
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) UiThreadImmediateExecutorService(com.facebook.common.executors.UiThreadImmediateExecutorService) TimeUnit(java.util.concurrent.TimeUnit) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)

Example 19 with FakeClock

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

the class SingleUsePostprocessorProducerTest 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 : Bitmap(android.graphics.Bitmap) CloseableStaticBitmap(com.facebook.imagepipeline.image.CloseableStaticBitmap) 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 20 with FakeClock

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

the class ThreadHandoffProducerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    mTestExecutorService = new TestExecutorService(new FakeClock());
    mThreadHandoffProducer = new ThreadHandoffProducer(mInputProducer, new ThreadHandoffProducerQueue(mTestExecutorService));
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) ThreadHandoffProducerQueue(com.facebook.imagepipeline.producers.ThreadHandoffProducerQueue)

Aggregations

FakeClock (com.facebook.imagepipeline.testing.FakeClock)20 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)17 Before (org.junit.Before)7 EncodedImage (com.facebook.imagepipeline.image.EncodedImage)6 TestScheduledExecutorService (com.facebook.imagepipeline.testing.TestScheduledExecutorService)5 CloseableReference (com.facebook.common.references.CloseableReference)4 File (java.io.File)3 Bitmap (android.graphics.Bitmap)2 TestAnimatedDrawableBackend (com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend)2 CloseableStaticBitmap (com.facebook.imagepipeline.image.CloseableStaticBitmap)2 InputStream (java.io.InputStream)2 Canvas (android.graphics.Canvas)1 Drawable (android.graphics.drawable.Drawable)1 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