FileDocCategorySizeDatePackage
MockContentResolver.javaAPI DocAndroid 5.1 API4658Thu Mar 12 22:22:42 GMT 2015android.test.mock

MockContentResolver

public class MockContentResolver extends android.content.ContentResolver

An extension of {@link android.content.ContentResolver} that is designed for testing.

MockContentResolver overrides Android's normal way of resolving providers by authority. To have access to a provider based on its authority, users of MockContentResolver first instantiate the provider and use {@link MockContentResolver#addProvider(String, ContentProvider)}. Resolution of an authority occurs entirely within MockContentResolver.

Users can also set an authority's entry in the map to null, so that a provider is completely mocked out.

Developer Guides

For more information about application testing, read the Testing developer guide.

Fields Summary
Map
mProviders
Constructors Summary
public MockContentResolver()
Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

        this(null);
    
public MockContentResolver(android.content.Context context)
Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

        super(context);
        mProviders = Maps.newHashMap();
    
Methods Summary
protected android.content.IContentProvideracquireExistingProvider(android.content.Context context, java.lang.String name)

hide


        /*
         * Gets the content provider from the local map
         */
        final ContentProvider provider = mProviders.get(name);

        if (provider != null) {
            return provider.getIContentProvider();
        } else {
            return null;
        }
    
protected android.content.IContentProvideracquireProvider(android.content.Context context, java.lang.String name)

hide

        return acquireExistingProvider(context, name);
    
protected android.content.IContentProvideracquireUnstableProvider(android.content.Context c, java.lang.String name)

hide

        return acquireProvider(c, name);
    
public voidaddProvider(java.lang.String name, android.content.ContentProvider provider)
Adds access to a provider based on its authority

param
name The authority name associated with the provider.
param
provider An instance of {@link android.content.ContentProvider} or one of its subclasses, or null.


        /*
         * Maps the authority to the provider locally.
         */
        mProviders.put(name, provider);
    
public voidnotifyChange(android.net.Uri uri, android.database.ContentObserver observer, boolean syncToNetwork)
Overrides {@link android.content.ContentResolver#notifyChange(Uri, ContentObserver, boolean) ContentResolver.notifChange(Uri, ContentObserver, boolean)}. All parameters are ignored. The method hides providers linked to MockContentResolver from other observers in the system.

param
uri (Ignored) The uri of the content provider.
param
observer (Ignored) The observer that originated the change.
param
syncToNetwork (Ignored) If true, attempt to sync the change to the network.

    
public booleanreleaseProvider(android.content.IContentProvider provider)

hide

        return true;
    
public booleanreleaseUnstableProvider(android.content.IContentProvider icp)

hide

        return releaseProvider(icp);
    
public voidunstableProviderDied(android.content.IContentProvider icp)

hide