FileDocCategorySizeDatePackage
ProviderTestCase.javaAPI DocAndroid 1.5 API3267Wed May 06 22:42:02 BST 2009android.test

ProviderTestCase

public 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}.
deprecated
this class extends InstrumentationTestCase but should extend AndroidTestCase. Use ProviderTestCase2, which corrects this problem, instead.

Fields Summary
Class
mProviderClass
String
mProviderAuthority
private IsolatedContext
mProviderContext
private android.test.mock.MockContentResolver
mResolver
private T
mProvider
The 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.MockContentResolvergetMockContentResolver()

        return mResolver;
    
public IsolatedContextgetMockContext()

        return mProviderContext;
    
public TgetProvider()

        return mProvider;
    
public static android.content.ContentResolvernewResolverWithContentProviderFromSql(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 voidsetUp()

        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());