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