Search in sources :

Example 21 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolverTest method acquireUnstableProvider_shouldReturnWithString.

@Test
public void acquireUnstableProvider_shouldReturnWithString() {
    ContentProvider cp = mock(ContentProvider.class);
    ShadowContentResolver.registerProviderInternal(AUTHORITY, cp);
    assertThat(contentResolver.acquireUnstableProvider(AUTHORITY)).isSameInstanceAs(cp.getIContentProvider());
}
Also used : ContentProvider(android.content.ContentProvider) Test(org.junit.Test)

Example 22 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolverTest method registerProvider_shouldAttachProviderInfo.

@Test
public void registerProvider_shouldAttachProviderInfo() {
    ContentProvider mock = mock(ContentProvider.class);
    ProviderInfo providerInfo0 = new ProviderInfo();
    // todo: support multiple authorities
    providerInfo0.authority = "the-authority";
    providerInfo0.grantUriPermissions = true;
    mock.attachInfo(ApplicationProvider.getApplicationContext(), providerInfo0);
    mock.onCreate();
    ArgumentCaptor<ProviderInfo> captor = ArgumentCaptor.forClass(ProviderInfo.class);
    verify(mock).attachInfo(same((Application) ApplicationProvider.getApplicationContext()), captor.capture());
    ProviderInfo providerInfo = captor.getValue();
    assertThat(providerInfo.authority).isEqualTo("the-authority");
    assertThat(providerInfo.grantUriPermissions).isEqualTo(true);
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) ContentProvider(android.content.ContentProvider) Application(android.app.Application) Test(org.junit.Test)

Example 23 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolver method query.

@Implementation
protected Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) {
    ContentProvider provider = getProvider(uri, getContext());
    if (provider != null) {
        return provider.query(uri, projection, selection, selectionArgs, sortOrder, cancellationSignal);
    } else {
        BaseCursor returnCursor = getCursor(uri);
        if (returnCursor == null) {
            return null;
        }
        returnCursor.setQuery(uri, projection, selection, selectionArgs, sortOrder);
        return returnCursor;
    }
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 24 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolver method query.

@Implementation(minSdk = O)
protected final Cursor query(Uri uri, String[] projection, Bundle queryArgs, CancellationSignal cancellationSignal) {
    ContentProvider provider = getProvider(uri, getContext());
    if (provider != null) {
        return provider.query(uri, projection, queryArgs, cancellationSignal);
    } else {
        BaseCursor returnCursor = getCursor(uri);
        if (returnCursor == null) {
            return null;
        }
        String selection = queryArgs.getString(QUERY_ARG_SQL_SELECTION);
        String[] selectionArgs = queryArgs.getStringArray(QUERY_ARG_SQL_SELECTION_ARGS);
        String sortOrder = queryArgs.getString(QUERY_ARG_SQL_SORT_ORDER);
        returnCursor.setQuery(uri, projection, selection, selectionArgs, sortOrder);
        return returnCursor;
    }
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 25 with ContentProvider

use of android.content.ContentProvider in project robolectric by robolectric.

the class ShadowContentResolver method update.

/**
 * If a {@link ContentProvider} is registered for the given {@link Uri}, its {@link
 * ContentProvider#update(Uri, ContentValues, String, String[])} method will be invoked.
 *
 * Tests can verify that this method was called using {@link #getStatements()} or {@link
 * #getUpdateStatements()}.
 *
 * @return If no appropriate {@link ContentProvider} is found, no action will be taken and 1 will
 *     be returned.
 */
@Implementation
protected int update(Uri uri, ContentValues values, String where, String[] selectionArgs) {
    ContentProvider provider = getProvider(uri, getContext());
    ContentValues valuesCopy = (values == null) ? null : new ContentValues(values);
    UpdateStatement updateStatement = new UpdateStatement(uri, provider, valuesCopy, where, selectionArgs);
    statements.add(updateStatement);
    updateStatements.add(updateStatement);
    if (provider != null) {
        return provider.update(uri, values, where, selectionArgs);
    } else {
        return 1;
    }
}
Also used : ContentValues(android.content.ContentValues) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Aggregations

ContentProvider (android.content.ContentProvider)53 Uri (android.net.Uri)28 IContentProvider (android.content.IContentProvider)16 Test (org.junit.Test)12 Implementation (org.robolectric.annotation.Implementation)11 ContentValues (android.content.ContentValues)8 Context (android.content.Context)7 ApplicationInfo (android.content.pm.ApplicationInfo)7 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)7 RemoteException (android.os.RemoteException)7 AndroidRuntimeException (android.util.AndroidRuntimeException)7 ComponentName (android.content.ComponentName)6 IBinder (android.os.IBinder)6 BaseCursor (org.robolectric.fakes.BaseCursor)6 ContentProviderOperation (android.content.ContentProviderOperation)4 OperationApplicationException (android.content.OperationApplicationException)4 ProviderInfo (android.content.pm.ProviderInfo)3 Cursor (android.database.Cursor)3 MatrixCursor (android.database.MatrixCursor)3 ContentProviderResult (android.content.ContentProviderResult)2