Search in sources :

Example 6 with FakeClock

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

the class LocalVideoThumbnailProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalVideoThumbnailProducer = new LocalVideoThumbnailProducer(mExecutor);
    mFile = new File(RuntimeEnvironment.application.getExternalFilesDir(null), TEST_FILENAME);
    mockStatic(ThumbnailUtils.class);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, false, Priority.MEDIUM);
    when(mImageRequest.getSourceFile()).thenReturn(mFile);
}
Also used : FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) File(java.io.File)

Example 7 with FakeClock

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

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

the class LocalAssetFetchProducerTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(mAssetManager.openFd(eq(TEST_FILENAME))).thenReturn(mAssetFileDescriptor);
    when(mAssetFileDescriptor.getLength()).thenReturn((long) TEST_DATA_LENGTH);
    when(mPooledByteBufferFactory.newByteBuffer(any(InputStream.class), eq(TEST_DATA_LENGTH))).thenReturn(mPooledByteBuffer);
    mExecutor = new TestExecutorService(new FakeClock());
    mLocalAssetFetchProducer = new LocalAssetFetchProducer(mExecutor, mPooledByteBufferFactory, mAssetManager);
    mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mock(Object.class), ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
    when(mImageRequest.getSourceUri()).thenReturn(Uri.parse("asset:///" + TEST_FILENAME));
    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 : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) EncodedImage(com.facebook.imagepipeline.image.EncodedImage)

Example 9 with FakeClock

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

the class DiskStorageCacheTest method setUp.

@Before
public void setUp() {
    mClock = mock(SystemClock.class);
    PowerMockito.mockStatic(SystemClock.class);
    PowerMockito.when(SystemClock.get()).thenReturn(mClock);
    mBackgroundExecutor = new TestExecutorService(new FakeClock());
    mDiskTrimmableRegistry = mock(DiskTrimmableRegistry.class);
    mCacheEventListener = mock(CacheEventListener.class);
    mCacheEventListenerInOrder = inOrder(mCacheEventListener);
    // we know the directory will be this
    mCacheDirectory = new File(RuntimeEnvironment.application.getCacheDir(), CACHE_TYPE);
    mCacheDirectory.mkdirs();
    if (!mCacheDirectory.exists()) {
        throw new RuntimeException(String.format((Locale) null, "Cannot create cache dir: %s: directory %s", mCacheDirectory.getAbsolutePath(), mCacheDirectory.exists() ? "already exists" : "does not exist"));
    }
    mStorage = createDiskStorage(TESTCACHE_VERSION_START_OF_VERSIONING);
    mCache = createDiskCache(mStorage, false);
    mCache.clearAll();
    reset(mCacheEventListener);
    verify(mDiskTrimmableRegistry).registerDiskTrimmable(mCache);
}
Also used : Locale(java.util.Locale) CacheEventListener(com.facebook.cache.common.CacheEventListener) SystemClock(com.facebook.common.time.SystemClock) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) DiskTrimmableRegistry(com.facebook.common.disk.DiskTrimmableRegistry) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Before(org.junit.Before)

Example 10 with FakeClock

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

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