Search in sources :

Example 6 with TestExecutorService

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

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

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

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

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

the class AnimatedRepeatedPostprocessorProducerTest 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)

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