Search in sources :

Example 1 with TestScheduledExecutorService

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

the class JobSchedulerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mFakeClockForTime = new FakeClock();
    mFakeClockForWorker = new FakeClock();
    mFakeClockForScheduled = new FakeClock();
    mFakeClockForTime.incrementBy(1000);
    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 mFakeClockForTime.now();
        }
    });
    mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClockForScheduled);
    PowerMockito.mockStatic(JobScheduler.JobStartExecutorSupplier.class);
    when(JobScheduler.JobStartExecutorSupplier.get()).thenReturn(mTestScheduledExecutorService);
    mTestJobRunnable = new TestJobRunnable();
    mJobScheduler = new JobScheduler(mTestExecutorService, mTestJobRunnable, INTERVAL);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) Before(org.junit.Before)

Example 2 with TestScheduledExecutorService

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

the class AnimatedDrawableTest method setup.

@Before
public void setup() {
    mFakeClock = new FakeClock();
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClock);
    mBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
    mCachingBackend = new TestAnimatedDrawableCachingBackend(mBackend);
    mCallback = new MyCallback(mFakeClock);
    mDrawable = new AnimatedDrawable(mTestScheduledExecutorService, mCachingBackend, AnimatedDrawableDiagnosticsNoop.getInstance(), mFakeClock);
    mDrawable.setCallback(mCallback);
}
Also used : TestAnimatedDrawableBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) Before(org.junit.Before)

Example 3 with TestScheduledExecutorService

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

the class AnimatedDrawableSupportTest method setup.

@Before
public void setup() {
    mFakeClock = new FakeClock();
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClock);
    mBackend = new TestAnimatedDrawableSupportBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
    mCachingBackend = new TestAnimatedDrawableCachingBackend(mBackend);
    mCallback = new MyCallback(mFakeClock);
    mDrawable = new AnimatedDrawableSupport(mTestScheduledExecutorService, mCachingBackend, AnimatedDrawableDiagnosticsNoop.getInstance(), mFakeClock);
    mDrawable.setCallback(mCallback);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) TestAnimatedDrawableSupportBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableSupportBackend) Before(org.junit.Before)

Example 4 with TestScheduledExecutorService

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

the class AnimationBackendDelegateWithInactivityCheckTest method setup.

@Before
public void setup() {
    mAnimationBackend = mock(AnimationBackend.class);
    mInactivityListener = mock(AnimationBackendDelegateWithInactivityCheck.InactivityListener.class);
    mParent = mock(Drawable.class);
    mCanvas = mock(Canvas.class);
    mFakeClock = new FakeClock();
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClock);
    mAnimationBackendDelegateWithInactivityCheck = AnimationBackendDelegateWithInactivityCheck.createForBackend(mAnimationBackend, mInactivityListener, mFakeClock, mTestScheduledExecutorService);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) Before(org.junit.Before)

Example 5 with TestScheduledExecutorService

use of com.facebook.imagepipeline.testing.TestScheduledExecutorService 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(NativeJpegTranscoder.class);
    PowerMockito.mockStatic(UiThreadImmediateExecutorService.class);
    when(UiThreadImmediateExecutorService.getInstance()).thenReturn(mUiThreadImmediateExecutorService);
    mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
    when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
    when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
    when(mProducerListener.requiresExtraMap(eq(mProducerContext), 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) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) UiThreadImmediateExecutorService(com.facebook.common.executors.UiThreadImmediateExecutorService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mockito.anyLong(org.mockito.Mockito.anyLong) TimeUnit(java.util.concurrent.TimeUnit) TrivialPooledByteBuffer(com.facebook.imagepipeline.testing.TrivialPooledByteBuffer) Before(org.junit.Before)

Aggregations

FakeClock (com.facebook.imagepipeline.testing.FakeClock)5 TestScheduledExecutorService (com.facebook.imagepipeline.testing.TestScheduledExecutorService)5 Before (org.junit.Before)5 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Canvas (android.graphics.Canvas)1 Drawable (android.graphics.drawable.Drawable)1 UiThreadImmediateExecutorService (com.facebook.common.executors.UiThreadImmediateExecutorService)1 TestAnimatedDrawableBackend (com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend)1 TestAnimatedDrawableSupportBackend (com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableSupportBackend)1 TrivialPooledByteBuffer (com.facebook.imagepipeline.testing.TrivialPooledByteBuffer)1 TimeUnit (java.util.concurrent.TimeUnit)1 Mockito.anyLong (org.mockito.Mockito.anyLong)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Answer (org.mockito.stubbing.Answer)1