Most visited

Recently visited

Added in API level 1

MockContentResolver

public class MockContentResolver
extends ContentResolver

java.lang.Object
   ↳ android.content.ContentResolver
     ↳ android.test.mock.MockContentResolver


An extension of 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 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.

Summary

Inherited constants

From class android.content.ContentResolver

Public constructors

MockContentResolver()

Creates a local map of providers.

MockContentResolver(Context context)

Creates a local map of providers.

Public methods

void addProvider(String name, ContentProvider provider)

Adds access to a provider based on its authority

void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork)

Overrides ContentResolver.notifChange(Uri, ContentObserver, boolean).

Inherited methods

From class android.content.ContentResolver
From class java.lang.Object

Public constructors

MockContentResolver

Added in API level 1
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.

MockContentResolver

Added in API level 18
MockContentResolver (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.

Parameters
context Context

Public methods

addProvider

Added in API level 1
void addProvider (String name, 
                ContentProvider provider)

Adds access to a provider based on its authority

Parameters
name String: The authority name associated with the provider.
provider ContentProvider: An instance of ContentProvider or one of its subclasses, or null.

notifyChange

Added in API level 1
void notifyChange (Uri uri, 
                ContentObserver observer, 
                boolean syncToNetwork)

Overrides ContentResolver.notifChange(Uri, ContentObserver, boolean). All parameters are ignored. The method hides providers linked to MockContentResolver from other observers in the system.

Parameters
uri Uri: (Ignored) The uri of the content provider.
observer ContentObserver: (Ignored) The observer that originated the change.
syncToNetwork boolean: (Ignored) If true, attempt to sync the change to the network.

Hooray!