use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolver method query.
@Implementation
protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
ContentProvider provider = getProvider(uri, getContext());
if (provider != null) {
return provider.query(uri, projection, selection, selectionArgs, sortOrder);
} else {
BaseCursor returnCursor = getCursor(uri);
if (returnCursor == null) {
return null;
}
returnCursor.setQuery(uri, projection, selection, selectionArgs, sortOrder);
return returnCursor;
}
}
use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolverTest method shouldDelegateCallsToRegisteredProvider.
@Test
public void shouldDelegateCallsToRegisteredProvider() {
ShadowContentResolver.registerProviderInternal(AUTHORITY, new ContentProvider() {
@Override
public boolean onCreate() {
return false;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return new BaseCursor();
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return -1;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return -1;
}
@Override
public String getType(Uri uri) {
return null;
}
});
final Uri uri = Uri.parse("content://" + AUTHORITY + "/some/path");
final Uri unrelated = Uri.parse("content://unrelated/some/path");
assertThat(contentResolver.query(uri, null, null, null, null)).isNotNull();
assertThat(contentResolver.insert(uri, new ContentValues())).isNull();
assertThat(contentResolver.delete(uri, null, null)).isEqualTo(-1);
assertThat(contentResolver.update(uri, new ContentValues(), null, null)).isEqualTo(-1);
assertThat(contentResolver.query(unrelated, null, null, null, null)).isNull();
assertThat(contentResolver.insert(unrelated, new ContentValues())).isNotNull();
assertThat(contentResolver.delete(unrelated, null, null)).isEqualTo(1);
assertThat(contentResolver.update(unrelated, new ContentValues(), null, null)).isEqualTo(1);
}
use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolverTest method whenCursorHasBeenSet_query_shouldReturnTheCursor.
@Test
public void whenCursorHasBeenSet_query_shouldReturnTheCursor() {
assertThat(shadowContentResolver.query(null, null, null, null, null)).isNull();
BaseCursor cursor = new BaseCursor();
shadowContentResolver.setCursor(cursor);
assertThat((BaseCursor) shadowContentResolver.query(null, null, null, null, null)).isSameInstanceAs(cursor);
}
Aggregations