Code example for MockContentResolver

Methods: addProvider

0
     * a new instance of {@link RestrictionMockContext}, which stubs out the 
     * security infrastructure. 
     */ 
    public ContactsActor(Context overallContext, String packageName,
            Class<? extends ContentProvider> providerClass, String authority) throws Exception {
        resolver = new MockContentResolver();
        context = new RestrictionMockContext(overallContext, packageName, resolver);
        this.packageName = packageName;
 
        RenamingDelegatingContext targetContextWrapper = new RenamingDelegatingContext(context,
                overallContext, FILENAME_PREFIX);
        mProviderContext = new IsolatedContext(resolver, targetContextWrapper);
        provider = addProvider(providerClass, authority);
    } 
 
    public void addAuthority(String authority) {
        resolver.addProvider(authority, provider);
    } 
 
    public ContentProvider addProvider(Class<? extends ContentProvider> providerClass,
            String authority) throws Exception {
        ContentProvider provider = providerClass.newInstance();
        provider.attachInfo(mProviderContext, null);
        resolver.addProvider(authority, provider);
        return provider;
    } 
 
    /** 
     * Mock {@link Context} that reports specific well-known values for testing 
Stop searching for code, let great code find you!  Add Codota to your java IDE