Code example for MockContentResolver

Methods: addProvider

0
        SynchronousContactsProvider2.resetOpenHelper(); 
    } 
 
    public void testPerformance() { 
        final Context targetContext = getContext();
        MockContentResolver resolver = new MockContentResolver();
        MockContext context = new MockContext() {
            @Override 
            public Resources getResources() {
                return targetContext.getResources();
            } 
 
            @Override 
            public String getPackageName() {
                return "no.package"; 
            } 
 
            @Override 
            public ApplicationInfo getApplicationInfo() {
                ApplicationInfo ai = new ApplicationInfo();
                ai.packageName = "contactsTestPackage";
                return ai;
            } 
        }; 
        RenamingDelegatingContext targetContextWrapper =
                new RenamingDelegatingContext(context, targetContext, "perf.");
        targetContextWrapper.makeExistingFilesAndDbsAccessible();
        IsolatedContext providerContext = new IsolatedContext(resolver, targetContextWrapper);
        SynchronousContactsProvider2 provider = new SynchronousContactsProvider2();
        provider.setDataWipeEnabled(false);
        provider.attachInfo(providerContext, null);
        resolver.addProvider(ContactsContract.AUTHORITY, provider);
 
        long rawContactCount = provider.getRawContactCount();
        if (rawContactCount == 0) {
            Log.w(TAG, "The test has not been set up. Use this command to copy a contact db"
                    + " to the device:\nadb push <large contacts2.db> "