Search in sources :

Example 11 with TestExecutorService

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

the class LocalContentUriFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalContentUriFetchProducer = new LocalContentUriFetchProducer(mExecutor, mPooledByteBufferFactory, mContentResolver);
    mContentUri = Uri.fromFile(mock(File.class));
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    when(mImageRequest.getSourceUri()).thenReturn(mContentUri);
    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 12 with TestExecutorService

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

the class LocalContentUriThumbnailFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalContentUriThumbnailFetchProducer = new LocalContentUriThumbnailFetchProducer(mExecutor, mPooledByteBufferFactory, mContentResolver);
    mContentUri = Uri.parse("content://media/external/images/media/1");
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    when(mImageRequest.getSourceUri()).thenReturn(mContentUri);
    mockMediaStoreCursor();
    mockThumbnailFile();
    mockContentResolver();
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService)

Example 13 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService 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 14 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService 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 15 with TestExecutorService

use of com.facebook.imagepipeline.testing.TestExecutorService 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)

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