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;
}
}
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);
}
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;
}
}
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;
}
}
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());
}
}
Aggregations