Search in sources :

Example 1 with ContentResolverShadow

use of com.bumptech.glide.tests.ContentResolverShadow in project glide by bumptech.

the class FileDescriptorLocalUriFetcherTest method testLoadResource_withNullFileDescriptor_callsLoadFailed.

@Test
public void testLoadResource_withNullFileDescriptor_callsLoadFailed() {
    Context context = RuntimeEnvironment.application;
    Uri uri = Uri.parse("file://nothing");
    ContentResolver contentResolver = context.getContentResolver();
    ContentResolverShadow shadow = (ContentResolverShadow) ShadowExtractor.extract(contentResolver);
    shadow.registerFileDescriptor(uri, null);
    FileDescriptorLocalUriFetcher fetcher = new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
    fetcher.loadData(Priority.NORMAL, callback);
    verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
Also used : Context(android.content.Context) FileNotFoundException(java.io.FileNotFoundException) FileDescriptorLocalUriFetcher(com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher) ContentResolverShadow(com.bumptech.glide.tests.ContentResolverShadow) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 2 with ContentResolverShadow

use of com.bumptech.glide.tests.ContentResolverShadow in project glide by bumptech.

the class FileDescriptorLocalUriFetcherTest method testLoadResource_returnsFileDescriptor.

@Test
public void testLoadResource_returnsFileDescriptor() throws Exception {
    Context context = RuntimeEnvironment.application;
    Uri uri = Uri.parse("file://nothing");
    ContentResolver contentResolver = context.getContentResolver();
    ContentResolverShadow shadow = (ContentResolverShadow) ShadowExtractor.extract(contentResolver);
    AssetFileDescriptor assetFileDescriptor = mock(AssetFileDescriptor.class);
    ParcelFileDescriptor parcelFileDescriptor = mock(ParcelFileDescriptor.class);
    when(assetFileDescriptor.getParcelFileDescriptor()).thenReturn(parcelFileDescriptor);
    shadow.registerFileDescriptor(uri, assetFileDescriptor);
    FileDescriptorLocalUriFetcher fetcher = new FileDescriptorLocalUriFetcher(context.getContentResolver(), uri);
    fetcher.loadData(Priority.NORMAL, callback);
    verify(callback).onDataReady(eq(parcelFileDescriptor));
}
Also used : Context(android.content.Context) AssetFileDescriptor(android.content.res.AssetFileDescriptor) ParcelFileDescriptor(android.os.ParcelFileDescriptor) FileDescriptorLocalUriFetcher(com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher) ContentResolverShadow(com.bumptech.glide.tests.ContentResolverShadow) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 3 with ContentResolverShadow

use of com.bumptech.glide.tests.ContentResolverShadow in project glide by bumptech.

the class StreamLocalUriFetcherTest method testLoadResource_returnsInputStream.

@Test
public void testLoadResource_returnsInputStream() throws Exception {
    Context context = RuntimeEnvironment.application;
    Uri uri = Uri.parse("file://nothing");
    ContentResolver contentResolver = context.getContentResolver();
    ContentResolverShadow shadow = (ContentResolverShadow) ShadowExtractor.extract(contentResolver);
    shadow.registerInputStream(uri, new ByteArrayInputStream(new byte[0]));
    StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
    fetcher.loadData(Priority.NORMAL, callback);
    verify(callback).onDataReady(isNotNull(InputStream.class));
}
Also used : Context(android.content.Context) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) StreamLocalUriFetcher(com.bumptech.glide.load.data.StreamLocalUriFetcher) ContentResolverShadow(com.bumptech.glide.tests.ContentResolverShadow) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 4 with ContentResolverShadow

use of com.bumptech.glide.tests.ContentResolverShadow in project glide by bumptech.

the class StreamLocalUriFetcherTest method testLoadResource_withNullInputStream_callsLoadFailed.

@Test
public void testLoadResource_withNullInputStream_callsLoadFailed() {
    Context context = RuntimeEnvironment.application;
    Uri uri = Uri.parse("file://nothing");
    ContentResolver contentResolver = context.getContentResolver();
    ContentResolverShadow shadow = (ContentResolverShadow) ShadowExtractor.extract(contentResolver);
    shadow.registerInputStream(uri, null);
    StreamLocalUriFetcher fetcher = new StreamLocalUriFetcher(context.getContentResolver(), uri);
    fetcher.loadData(Priority.LOW, callback);
    verify(callback).onLoadFailed(isA(FileNotFoundException.class));
}
Also used : Context(android.content.Context) FileNotFoundException(java.io.FileNotFoundException) StreamLocalUriFetcher(com.bumptech.glide.load.data.StreamLocalUriFetcher) ContentResolverShadow(com.bumptech.glide.tests.ContentResolverShadow) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Aggregations

ContentResolver (android.content.ContentResolver)4 Context (android.content.Context)4 Uri (android.net.Uri)4 ContentResolverShadow (com.bumptech.glide.tests.ContentResolverShadow)4 Test (org.junit.Test)4 FileDescriptorLocalUriFetcher (com.bumptech.glide.load.data.FileDescriptorLocalUriFetcher)2 StreamLocalUriFetcher (com.bumptech.glide.load.data.StreamLocalUriFetcher)2 FileNotFoundException (java.io.FileNotFoundException)2 AssetFileDescriptor (android.content.res.AssetFileDescriptor)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1