use of com.facebook.common.internal.Predicate in project fresco by facebook.
the class ImagePipelineTest method testEvictFromMemoryCache.
@Test
public void testEvictFromMemoryCache() {
String uriString = "http://dummy/string";
Uri uri = Uri.parse(uriString);
mImagePipeline.evictFromMemoryCache(uri);
CacheKey dummyCacheKey = mock(CacheKey.class);
ArgumentCaptor<Predicate> bitmapCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mBitmapMemoryCache).removeAll(bitmapCachePredicateCaptor.capture());
Predicate<CacheKey> bitmapMemoryCacheKeyPredicate = bitmapCachePredicateCaptor.getValue();
BitmapMemoryCacheKey bitmapMemoryCacheKey1 = mock(BitmapMemoryCacheKey.class);
BitmapMemoryCacheKey bitmapMemoryCacheKey2 = mock(BitmapMemoryCacheKey.class);
when(bitmapMemoryCacheKey1.containsUri(uri)).thenReturn(true);
when(bitmapMemoryCacheKey2.containsUri(uri)).thenReturn(false);
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey1));
assertFalse(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey2));
assertFalse(bitmapMemoryCacheKeyPredicate.apply(dummyCacheKey));
ArgumentCaptor<Predicate> encodedMemoryCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mEncodedMemoryCache).removeAll(encodedMemoryCachePredicateCaptor.capture());
Predicate<CacheKey> encodedMemoryCacheKeyPredicate = encodedMemoryCachePredicateCaptor.getValue();
SimpleCacheKey simpleCacheKey1 = new SimpleCacheKey(uriString);
SimpleCacheKey simpleCacheKey2 = new SimpleCacheKey("rubbish");
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey1));
assertFalse(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey2));
assertFalse(encodedMemoryCacheKeyPredicate.apply(dummyCacheKey));
}
use of com.facebook.common.internal.Predicate in project fresco by facebook.
the class ImagePipelineTest method testClearMemoryCaches.
@Test
public void testClearMemoryCaches() {
String uriString = "http://dummy/string";
Uri uri = Uri.parse(uriString);
CacheKey dummyCacheKey = mock(CacheKey.class);
mImagePipeline.clearMemoryCaches();
ArgumentCaptor<Predicate> bitmapCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mBitmapMemoryCache).removeAll(bitmapCachePredicateCaptor.capture());
Predicate<CacheKey> bitmapMemoryCacheKeyPredicate = bitmapCachePredicateCaptor.getValue();
BitmapMemoryCacheKey bitmapMemoryCacheKey1 = mock(BitmapMemoryCacheKey.class);
BitmapMemoryCacheKey bitmapMemoryCacheKey2 = mock(BitmapMemoryCacheKey.class);
when(bitmapMemoryCacheKey1.containsUri(uri)).thenReturn(true);
when(bitmapMemoryCacheKey2.containsUri(uri)).thenReturn(false);
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey1));
assertTrue(bitmapMemoryCacheKeyPredicate.apply(bitmapMemoryCacheKey2));
assertTrue(bitmapMemoryCacheKeyPredicate.apply(dummyCacheKey));
ArgumentCaptor<Predicate> encodedMemoryCachePredicateCaptor = ArgumentCaptor.forClass(Predicate.class);
verify(mEncodedMemoryCache).removeAll(encodedMemoryCachePredicateCaptor.capture());
Predicate<CacheKey> encodedMemoryCacheKeyPredicate = encodedMemoryCachePredicateCaptor.getValue();
SimpleCacheKey simpleCacheKey1 = new SimpleCacheKey(uriString);
SimpleCacheKey simpleCacheKey2 = new SimpleCacheKey("rubbish");
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey1));
assertTrue(encodedMemoryCacheKeyPredicate.apply(simpleCacheKey2));
assertTrue(encodedMemoryCacheKeyPredicate.apply(dummyCacheKey));
}
Aggregations