to top
Android APIs
public class

MockContentResolver

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

Class Overview

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

[Expand]
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)
[Expand]
Inherited Methods
From class android.content.ContentResolver
From class java.lang.Object

Public Constructors

public MockContentResolver ()

Added in API level 1

Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

public MockContentResolver (Context context)

Added in API level 18

Creates a local map of providers. This map is used instead of the global map when an API call tries to acquire a provider.

Public Methods

public void addProvider (String name, ContentProvider provider)

Added in API level 1

Adds access to a provider based on its authority

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

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

Added in API level 1

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 (Ignored) The uri of the content provider.
observer (Ignored) The observer that originated the change.
syncToNetwork (Ignored) If true, attempt to sync the change to the network.