Example usage for android.test.mock MockContentResolver MockContentResolver

List of usage examples for android.test.mock MockContentResolver MockContentResolver

Introduction

In this page you can find the example usage for android.test.mock MockContentResolver MockContentResolver.

Prototype

public MockContentResolver() 

Source Link

Document

Creates a local map of providers.

Usage

From source file:org.ohmage.activity.test.ResponseHistoryTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    getInstrumentation().waitForIdleSync();

    MockContentResolver fake = new MockContentResolver();
    provider = new DelegatingMockContentProvider(OhmageApplication.getContext(), DbContract.CONTENT_AUTHORITY) {

        @Override/*from ww  w. ja v a 2 s .  c o  m*/
        public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                String sortOrder) {
            switch (OhmageUriMatcher.getMatcher().match(uri)) {
            case OhmageUriMatcher.CAMPAIGNS:
                return new CampaignCursor(projection, campaigns);
            case OhmageUriMatcher.CAMPAIGN_SURVEYS:
                if (Campaigns.getCampaignUrn(uri).equals("urn:campaign:1"))
                    return new SurveyCursor(projection, surveys1);
                return new SurveyCursor(projection, surveys);
            case OhmageUriMatcher.RESPONSES:
                return new ResponseCursor(projection, new Response[8]);
            case OhmageUriMatcher.CAMPAIGN_RESPONSES:
                return new ResponseCursor(projection, responses4);
            case OhmageUriMatcher.CAMPAIGN_SURVEY_RESPONSES:
                if (Surveys.getSurveyId(uri).equals("Survey #3") && selection != null)
                    return new EmptyMockCursor();
                return new ResponseCursor(projection, responses2);
            case OhmageUriMatcher.RESPONSE_BY_PID:
                return new ResponseCursor(projection);
            default:
                return new EmptyMockCursor();
            }
        }
    };
    provider.addToContentResolver(fake);

    OhmageApplication.setFakeContentResolver(fake);
    solo = new Solo(getInstrumentation(), getActivity());
}

From source file:io.pivotal.arca.dispatcher.test.SupportRequestDispatcherTest.java

private RequestDispatcher getDispatcher() {
    final MockContentResolver resolver = new MockContentResolver();
    resolver.addProvider(AUTHORITY, mProvider);
    final RequestExecutor executor = new RequestExecutor.DefaultRequestExecutor(resolver);
    return new SupportRequestDispatcher(executor, getContext(), mLoaderManager);
}