Code example for MockContentResolver

Methods: addProvider

    public void testPerformance() { 
        final Context targetContext = getContext();
        MockContentResolver resolver = new MockContentResolver();
        MockContext context = new MockContext() {
            public Resources getResources() {
                return targetContext.getResources();
            public String getPackageName() {
                return "no.package"; 
            public ApplicationInfo getApplicationInfo() {
                ApplicationInfo ai = new ApplicationInfo();
                ai.packageName = "contactsTestPackage";
                return ai;
        RenamingDelegatingContext targetContextWrapper =
                new RenamingDelegatingContext(context, targetContext, "perf.");
        IsolatedContext providerContext = new IsolatedContext(resolver, targetContextWrapper);
        SynchronousContactsProvider2 provider = new SynchronousContactsProvider2();
        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> " 
Contextual code suggestions in your IDE  Get Codota for Java