Added in API level 8

MockContentProvider

open class MockContentProvider : ContentProvider
kotlin.Any
   ↳ android.content.ContentProvider
   ↳ android.test.mock.MockContentProvider

Mock implementation of ContentProvider. All methods are non-functional and throw java.lang.UnsupportedOperationException. Tests can extend this class to implement behavior needed for tests.

Summary

Inherited constants
Public constructors

A constructor accepting a Context instance, which is supposed to be the subclasss of MockContext.

MockContentProvider(context: Context!, readPermission: String!, writePermission: String!, pathPermissions: Array<PathPermission!>!)

A constructor which initialize four member variables which android.content.ContentProvider have internally.

Protected constructors

A constructor using MockContext instance as a Context in it.

Public methods
open Array<ContentProviderResult!>

open Unit
attachInfo(context: Context!, info: ProviderInfo!)

open static Unit
attachInfoForTesting(provider: ContentProvider!, context: Context!, providerInfo: ProviderInfo!)

Like attachInfo(android.content.Context,android.content.pm.ProviderInfo), but for use when directly instantiating the provider for testing.

open Int
bulkInsert(uri: Uri, values: Array<ContentValues!>)

If you're reluctant to implement this manually, please just call super.

open Int
delete(uri: Uri, selection: String?, selectionArgs: Array<String!>?)

open Array<String!>?
getStreamTypes(url: Uri, mimeTypeFilter: String)

open String?
getType(uri: Uri)

open String?

open Uri?
insert(uri: Uri, values: ContentValues?)

open Boolean

open AssetFileDescriptor?
openTypedAssetFile(url: Uri, mimeType: String, opts: Bundle?)

open Cursor?
query(uri: Uri, projection: Array<String!>?, selection: String?, selectionArgs: Array<String!>?, sortOrder: String?)

open Int
update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<String!>?)

Inherited functions

Public constructors

MockContentProvider

Added in API level 8
MockContentProvider(context: Context!)

A constructor accepting a Context instance, which is supposed to be the subclasss of MockContext.

MockContentProvider

Added in API level 8
MockContentProvider(
    context: Context!,
    readPermission: String!,
    writePermission: String!,
    pathPermissions: Array<PathPermission!>!)

A constructor which initialize four member variables which android.content.ContentProvider have internally.

Parameters
context Context!: A Context object which should be some mock instance (like the instance of android.test.mock.MockContext).
readPermission String!: The read permision you want this instance should have in the test, which is available via getReadPermission().
writePermission String!: The write permission you want this instance should have in the test, which is available via getWritePermission().
pathPermissions Array<PathPermission!>!: The PathPermissions you want this instance should have in the test, which is available via getPathPermissions().

Protected constructors

MockContentProvider

Added in API level 8
protected MockContentProvider()

A constructor using MockContext instance as a Context in it.

Public methods

applyBatch

Added in API level 8
open fun applyBatch(operations: ArrayList<ContentProviderOperation!>): Array<ContentProviderResult!>
Parameters
operations ArrayList<ContentProviderOperation!>: This value cannot be null.
Return
Array<ContentProviderResult!> This value cannot be null.

attachInfo

Added in API level 8
open fun attachInfo(
    context: Context!,
    info: ProviderInfo!
): Unit
Parameters
context Context!: The context this provider is running in
info ProviderInfo!: Registered information about this content provider

attachInfoForTesting

open static fun attachInfoForTesting(
    provider: ContentProvider!,
    context: Context!,
    providerInfo: ProviderInfo!
): Unit

Deprecated: Use a mocking framework like Mockito. New tests should be written using the Android Testing Support Library.

Like attachInfo(android.content.Context,android.content.pm.ProviderInfo), but for use when directly instantiating the provider for testing.

Provided for use by android.test.ProviderTestCase2 and android.test.RenamingDelegatingContext.

bulkInsert

Added in API level 8
open fun bulkInsert(
    uri: Uri,
    values: Array<ContentValues!>
): Int

If you're reluctant to implement this manually, please just call super.bulkInsert().

Parameters
uri Uri: The content:// URI of the insertion request. This value cannot be null.
values Array<ContentValues!>: An array of sets of column_name/value pairs to add to the database. This must not be null.
Return
Int The number of values that were inserted.

delete

Added in API level 8
open fun delete(
    uri: Uri,
    selection: String?,
    selectionArgs: Array<String!>?
): Int
Parameters
uri Uri: The full URI to query, including a row ID (if a specific record is requested). This value cannot be null.
selection String?: An optional restriction to apply to rows when deleting. This value may be null.
selectionArgs Array<String!>?: This value may be null.
Return
Int The number of rows affected.
Exceptions
android.database.SQLException

getStreamTypes

Added in API level 11
open fun getStreamTypes(
    url: Uri,
    mimeTypeFilter: String
): Array<String!>?
Parameters
uri The data in the content provider being queried. This value cannot be null.
mimeTypeFilter String: The type of data the client desires. May be a pattern, such as */* to retrieve all possible data types. This value cannot be null.
Return
Array<String!>? Returns null if there are no possible data streams for the given mimeTypeFilter. Otherwise returns an array of all available concrete MIME types.

getType

Added in API level 8
open fun getType(uri: Uri): String?
Parameters
uri Uri: the URI to query. This value cannot be null.
Return
String? a MIME type string, or null if there is no type.

getTypeAnonymous

Added in API level 34
open fun getTypeAnonymous(uri: Uri): String?
Parameters
uri Uri: the URI to query. This value cannot be null.
Return
String? a MIME type string, or null if type needs to be protected.

insert

Added in API level 8
open fun insert(
    uri: Uri,
    values: ContentValues?
): Uri?
Parameters
uri Uri: The content:// URI of the insertion request. This value cannot be null.
values ContentValues?: A set of column_name/value pairs to add to the database. This value may be null.
Return
Uri? The URI for the newly inserted item. This value may be null.

onCreate

Added in API level 8
open fun onCreate(): Boolean
Return
Boolean true if the provider was successfully loaded, false otherwise

openTypedAssetFile

Added in API level 11
open fun openTypedAssetFile(
    url: Uri,
    mimeType: String,
    opts: Bundle?
): AssetFileDescriptor?
Parameters
uri The data in the content provider being queried. This value cannot be null.
mimeTypeFilter The type of data the client desires. May be a pattern, such as */*, if the caller does not have specific type requirements; in this case the content provider will pick its best type matching the pattern. This value cannot be null.
opts Bundle?: Additional options from the client. The definitions of these are specific to the content provider being called. This value may be null.
Return
AssetFileDescriptor? Returns a new AssetFileDescriptor from which the client can read data of the desired type. This value may be null.
Exceptions
java.io.FileNotFoundException Throws FileNotFoundException if there is no file associated with the given URI or the mode is invalid.
java.lang.SecurityException Throws SecurityException if the caller does not have permission to access the data.
java.lang.IllegalArgumentException Throws IllegalArgumentException if the content provider does not support the requested MIME type.

query

Added in API level 8
open fun query(
    uri: Uri,
    projection: Array<String!>?,
    selection: String?,
    selectionArgs: Array<String!>?,
    sortOrder: String?
): Cursor?
Parameters
uri Uri: The URI to query. This will be the full URI sent by the client; if the client is requesting a specific record, the URI will end in a record number that the implementation should parse and add to a WHERE or HAVING clause, specifying that _id value. This value cannot be null.
projection Array<String!>?: The list of columns to put into the cursor. If null all columns are included.
selection String?: A selection criteria to apply when filtering rows. If null then all rows are included.
selectionArgs Array<String!>?: You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings. This value may be null.
sortOrder String?: How the rows in the cursor should be sorted. If null then the provider is free to define the sort order.
Return
Cursor? a Cursor or null.

update

Added in API level 8
open fun update(
    uri: Uri,
    values: ContentValues?,
    selection: String?,
    selectionArgs: Array<String!>?
): Int
Parameters
uri Uri: The URI to query. This can potentially have a record ID if this is an update request for a specific record. This value cannot be null.
values ContentValues?: A set of column_name/value pairs to update in the database. This value may be null.
selection String?: An optional filter to match rows to update. This value may be null.
selectionArgs Array<String!>?: This value may be null.
Return
Int the number of rows affected.