ProviderTestCasepublic abstract class ProviderTestCase extends InstrumentationTestCase If you would like to test a single content provider with an
{@link InstrumentationTestCase}, this provides some of the boiler plate in {@link #setUp} and
{@link #tearDown}. |
Fields Summary |
---|
Class | mProviderClass | String | mProviderAuthority | private IsolatedContext | mProviderContext | private android.test.mock.MockContentResolver | mResolver | private T | mProviderThe content provider that will be set up for use in each test method. |
Constructors Summary |
---|
public ProviderTestCase(Class providerClass, String providerAuthority)
mProviderClass = providerClass;
mProviderAuthority = providerAuthority;
|
Methods Summary |
---|
public android.test.mock.MockContentResolver | getMockContentResolver()
return mResolver;
| public IsolatedContext | getMockContext()
return mProviderContext;
| public T | getProvider()
return mProvider;
| public static android.content.ContentResolver | newResolverWithContentProviderFromSql(android.content.Context targetContext, java.lang.Class providerClass, java.lang.String authority, java.lang.String databaseName, int databaseVersion, java.lang.String sql)
final String filenamePrefix = "test.";
MockContentResolver resolver = new MockContentResolver();
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(
new MockContext(), // The context that most methods are delegated to
targetContext, // The context that file methods are delegated to
filenamePrefix);
Context context = new IsolatedContext(
resolver, targetContextWrapper);
DatabaseUtils.createDbFromSqlStatements(context, databaseName, databaseVersion, sql);
T provider = providerClass.newInstance();
provider.attachInfo(context, null);
resolver.addProvider(authority, provider);
return resolver;
| protected void | setUp()
super.setUp();
mResolver = new MockContentResolver();
final String filenamePrefix = "test.";
RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(
new MockContext(), // The context that most methods are delegated to
getInstrumentation().getTargetContext(), // The context that file methods are delegated to
filenamePrefix);
mProviderContext = new IsolatedContext(mResolver, targetContextWrapper);
mProvider = mProviderClass.newInstance();
mProvider.attachInfo(mProviderContext, null);
assertNotNull(mProvider);
mResolver.addProvider(mProviderAuthority, getProvider());
|
|