public class

ProviderTestRule.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.test.rule.provider.ProviderTestRule.Builder

Overview

A Builder to ease ProviderTestRule creation. Users can input one or more ContentProviders and their corresponding authority for tests. It also allows to specify the prefix to use when renaming test files for isolation by ProviderTestRule.Builder.setPrefix(String). If the ContentProvider under test is implemented based on SQLiteDatabase, users can also pass in database file to restore or database commands to run before tests.

Summary

Constructors
publicBuilder(java.lang.Class<ContentProvider> providerClass, java.lang.String providerAuth)

The basic builder to use when creating a ProviderTestRule, which allows to specify one ContentProvider and the corresponding authority for tests.

Methods
public ProviderTestRule.BuilderaddProvider(java.lang.Class<ContentProvider> providerClass, java.lang.String providerAuth)

Allows to add additional ContentProvider and the corresponding authority for testing.

public ProviderTestRulebuild()

public ProviderTestRule.BuildersetDatabaseCommands(java.lang.String dbName, java.lang.String dbCmds[])

Allows to pass in specific SQL commands to run against the database with a given name.

public ProviderTestRule.BuildersetDatabaseCommandsFile(java.lang.String dbName, java.io.File dbCmdFile)

Allows to pass in a file containing commands to run against the database with a given name.

public ProviderTestRule.BuildersetDatabaseFile(java.lang.String dbName, java.io.File dbDataFile)

Allows to pass in a SQLite database file containing the intended initial data to restore.

public ProviderTestRule.BuildersetPrefix(java.lang.String prefix)

Enables users to specify the prefix to use when renaming test files for isolation.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(java.lang.Class<ContentProvider> providerClass, java.lang.String providerAuth)

The basic builder to use when creating a ProviderTestRule, which allows to specify one ContentProvider and the corresponding authority for tests.

Parameters:

providerClass: The class of ContentProvider under test.
providerAuth: The authority defined for ContentProvider under test.

Methods

public ProviderTestRule.Builder setPrefix(java.lang.String prefix)

Enables users to specify the prefix to use when renaming test files for isolation. If not used, this rule will use "#DEFAULT_PREFIX" by default.

Parameters:

prefix: The non-empty prefix to append to test files.

public ProviderTestRule.Builder setDatabaseFile(java.lang.String dbName, java.io.File dbDataFile)

Allows to pass in a SQLite database file containing the intended initial data to restore.

Note: Restoring the database from the file are executed before any sql commands execution in SQLiteOpenHelper's onCreate method defined in ContentProvider under test, also before running the database commands, if any, passed in via ProviderTestRule.Builder.setDatabaseCommands(String, String...) and ProviderTestRule.Builder.setDatabaseCommandsFile(String, File).

In the case of the database file with prefixed name already exists, the database restoration will overwrite existing file.

Parameters:

dbName: The name of the underlying database used by the ContentProvider under test.
dbDataFile: The SQLite database file that contains the data to restore.

public ProviderTestRule.Builder setDatabaseCommands(java.lang.String dbName, java.lang.String dbCmds[])

Allows to pass in specific SQL commands to run against the database with a given name.

Note: The passed in commands are executed before any sql commands execution in SQLiteOpenHelper's onCreate method defined in ContentProvider under test, also before executing commands, if any, passed in via ProviderTestRule.Builder.setDatabaseCommandsFile(String, File), but after restoring the database file, if any, passed in via ProviderTestRule.Builder.setDatabaseFile(String, File).

Parameters:

dbName: The name of the underlying database used by the ContentProvider under test.
dbCmds: The SQL commands to run. Each command will be passed to SQLiteDatabase to execute.

public ProviderTestRule.Builder setDatabaseCommandsFile(java.lang.String dbName, java.io.File dbCmdFile)

Allows to pass in a file containing commands to run against the database with a given name.

Note: Commands in the file are executed before any sql commands execution in SQLiteOpenHelper's onCreate method defined in ContentProvider under test, but after restoring the database file, if any, passed in via ProviderTestRule.Builder.setDatabaseFile(String, File) and executing commands, if any, passed in via ProviderTestRule.Builder.setDatabaseCommands(String, String...).

Parameters:

dbName: The name of the underlying database used by the ContentProvider under test.
dbCmdFile: The file that contains line separated database commands to run. Each line will be treated as a separate command and passed to SQLiteDatabase to execute.

public ProviderTestRule.Builder addProvider(java.lang.Class<ContentProvider> providerClass, java.lang.String providerAuth)

Allows to add additional ContentProvider and the corresponding authority for testing. Similarly, ProviderTestRule.Builder.setDatabaseFile(String, File), ProviderTestRule.Builder.setDatabaseCommands(String, String...), ProviderTestRule.Builder.setDatabaseCommandsFile(String, File), and ProviderTestRule.runDatabaseCommands(String, String...) can be used for this ContentProvider.

Parameters:

providerClass: The class of the added ContentProvider under test.
providerAuth: The authority defined for the added ContentProvider under test.

public ProviderTestRule build()