Search in sources :

Example 26 with ContentProvider

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

the class ShadowContentResolver method delete.

/**
 * If a {@link ContentProvider} is registered for the given {@link Uri}, its {@link
 * ContentProvider#delete(Uri, String, String[])} method will be invoked.
 *
 * Tests can verify that this method was called using {@link #getDeleteStatements()} or {@link
 * #getDeletedUris()}.
 *
 * If no appropriate {@link ContentProvider} is found, no action will be taken and {@code 1}
 * will be returned.
 */
@Implementation
protected final int delete(Uri url, String where, String[] selectionArgs) {
    ContentProvider provider = getProvider(url, getContext());
    DeleteStatement deleteStatement = new DeleteStatement(url, provider, where, selectionArgs);
    statements.add(deleteStatement);
    deleteStatements.add(deleteStatement);
    if (provider != null) {
        return provider.delete(url, where, selectionArgs);
    } else {
        return 1;
    }
}
Also used : IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 27 with ContentProvider

use of android.content.ContentProvider in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class AvatarViewMixinTest method callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar.

@Test
public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() {
    final ContentResolver contentResolver = mContext.getContentResolver();
    final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(DUMMY_AUTHORITY).build();
    final ContentProvider mockContentProvider = mock(ContentProvider.class);
    ShadowContentResolver.registerProviderInternal(DUMMY_AUTHORITY, mockContentProvider);
    final Bundle bundle = new Bundle();
    final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    bundle.putParcelable("account_avatar", bitmap);
    bundle.putString("account_name", DUMMY_ACCOUNT);
    doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(), any(Bundle.class));
    contentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR, null, /* arg */
    null);
    final Object object = bundle.getParcelable("account_avatar");
    assertThat(object instanceof Bitmap).isTrue();
    assertThat(bundle.getString("account_name")).isEqualTo(DUMMY_ACCOUNT);
}
Also used : Bitmap(android.graphics.Bitmap) ContentProvider(android.content.ContentProvider) Bundle(android.os.Bundle) Uri(android.net.Uri) ShadowContentResolver(org.robolectric.shadows.ShadowContentResolver) ContentResolver(android.content.ContentResolver) BatteryFixSliceTest(com.android.settings.homepage.contextualcards.slices.BatteryFixSliceTest) Test(org.junit.Test)

Example 28 with ContentProvider

use of android.content.ContentProvider in project wire-android by wireapp.

the class ShadowContentResolver2 method delete.

// @Implementation
// public final ContentProviderClient acquireContentProviderClient(String name) {
// ContentProvider provider = getProvider(name);
// if (provider == null) return null;
// return getContentProviderClient(provider, true);
// }
// 
// @Implementation
// public final ContentProviderClient acquireContentProviderClient(Uri uri) {
// ContentProvider provider = getProvider(uri);
// if (provider == null) return null;
// return getContentProviderClient(provider, true);
// }
// 
// @Implementation
// public final ContentProviderClient acquireUnstableContentProviderClient(String name) {
// ContentProvider provider = getProvider(name);
// if (provider == null) return null;
// return getContentProviderClient(provider, false);
// }
// 
// @Implementation
// public final ContentProviderClient acquireUnstableContentProviderClient(Uri uri) {
// ContentProvider provider = getProvider(uri);
// if (provider == null) return null;
// return getContentProviderClient(provider, false);
// }
// 
// private ContentProviderClient getContentProviderClient(ContentProvider provider, boolean stable) {
// ContentProviderClient client =
// Robolectric.newInstance(ContentProviderClient.class,
// new Class[] {ContentResolver.class, IContentProvider.class, boolean.class},
// new Object[] {realContentResolver, provider.getIContentProvider(), stable});
// Robolectric.shadowOf(client).setContentProvider(provider);
// return client;
// }
// @Implementation
// public final IContentProvider acquireProvider(String name) {
// return acquireUnstableProvider(name);
// }
// 
// @Implementation
// public final IContentProvider acquireProvider(Uri uri) {
// return acquireUnstableProvider(uri);
// }
// @Implementation
// public final IContentProvider acquireUnstableProvider(String name) {
// ContentProvider cp = getProvider(name);
// if (cp != null) {
// return cp.getIContentProvider();
// }
// return null;
// }
// 
// @Implementation
// public final IContentProvider acquireUnstableProvider(Uri uri) {
// ContentProvider cp = getProvider(uri);
// if (cp != null) {
// return cp.getIContentProvider();
// }
// return null;
// }
@Implementation
public final int delete(Uri url, String where, String[] selectionArgs) {
    ContentProvider provider = getProvider(url);
    if (provider != null) {
        return provider.delete(url, where, selectionArgs);
    } else {
        DeleteStatement deleteStatement = new DeleteStatement(url, where, selectionArgs);
        deleteStatements.add(deleteStatement);
        return 1;
    }
}
Also used : ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 29 with ContentProvider

use of android.content.ContentProvider in project wire-android by wireapp.

the class ShadowContentResolver2 method query.

@Implementation
public final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    ContentProvider provider = getProvider(uri);
    if (provider != null) {
        return provider.query(uri, projection, selection, selectionArgs, sortOrder);
    } else {
        TestCursor returnCursor = getCursor(uri);
        if (returnCursor == null) {
            return null;
        }
        returnCursor.setQuery(uri, projection, selection, selectionArgs, sortOrder);
        return returnCursor;
    }
}
Also used : TestCursor(org.robolectric.tester.android.database.TestCursor) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 30 with ContentProvider

use of android.content.ContentProvider in project wire-android by wireapp.

the class ShadowContentResolver2 method createAndInitialize.

private static ContentProvider createAndInitialize(ContentProviderData providerData) {
    try {
        ContentProvider provider = (ContentProvider) Class.forName(providerData.getClassName()).newInstance();
        provider.onCreate();
        return provider;
    } catch (InstantiationException e) {
        throw new RuntimeException("Error instantiating class " + providerData.getClassName());
    } catch (IllegalAccessException e) {
        throw new RuntimeException("Error instantiating class " + providerData.getClassName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("Error instantiating class " + providerData.getClassName());
    }
}
Also used : ContentProvider(android.content.ContentProvider)

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