{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
public class ProviderTestRule.Builder
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 setPrefix. 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.
Public constructors |
|
|---|---|
<T extends ContentProvider> Builder(The basic builder to use when creating a |
|
Public methods |
|
|---|---|
@NonNull ProviderTestRule.Builder |
<T extends ContentProvider> addProvider(Allows to add additional ContentProvider and the corresponding authority for testing. |
@NonNull ProviderTestRule |
build() |
@NonNull ProviderTestRule.Builder |
Allows to pass in specific SQL commands to run against the database with a given name. |
@NonNull ProviderTestRule.Builder |
setDatabaseCommandsFile(@NonNull String dbName, @NonNull File dbCmdFile)Allows to pass in a file containing commands to run against the database with a given name. |
@NonNull ProviderTestRule.Builder |
setDatabaseFile(@NonNull String dbName, @NonNull File dbDataFile)Allows to pass in a SQLite database file containing the intended initial data to restore. |
@NonNull ProviderTestRule.Builder |
Enables users to specify the prefix to use when renaming test files for isolation. |
public <T extends ContentProvider> Builder(
@NonNull Class<@NonNull T> providerClass,
@NonNull String providerAuth
)
The basic builder to use when creating a ProviderTestRule, which allows to specify one ContentProvider and the corresponding authority for tests.
@NonNull
public ProviderTestRule.Builder <T extends ContentProvider> addProvider(
@NonNull Class<@NonNull T> providerClass,
@NonNull String providerAuth
)
Allows to add additional ContentProvider and the corresponding authority for testing. Similarly, setDatabaseFile, setDatabaseCommands, , and runDatabaseCommands can be used for this ContentProvider.
@NonNull
public ProviderTestRule.Builder setDatabaseCommands(
@NonNull String dbName,
@NonNull Array<@NonNull 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 setDatabaseCommandsFile, but after restoring the database file, if any, passed in via setDatabaseFile.
@NonNull
public ProviderTestRule.Builder setDatabaseCommandsFile(@NonNull String dbName, @NonNull 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 setDatabaseFile and executing commands, if any, passed in via setDatabaseCommands.
@NonNull
public ProviderTestRule.Builder setDatabaseFile(@NonNull String dbName, @NonNull 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 setDatabaseCommands and setDatabaseCommandsFile.
In the case of the database file with prefixed name already exists, the database restoration will overwrite existing file.
@NonNull
public ProviderTestRule.Builder setPrefix(@NonNull 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.