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());
}
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();
}
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());
}
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);
}
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();
}
Aggregations