use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolverTest method whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor.
@Test
public void whenCursorHasBeenSet_queryWithCancellationSignal_shouldReturnTheCursor() {
assertThat(shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isNull();
BaseCursor cursor = new BaseCursor();
shadowContentResolver.setCursor(cursor);
assertThat((BaseCursor) shadowContentResolver.query(null, null, null, null, null, new CancellationSignal())).isSameInstanceAs(cursor);
}
use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolverTest method getType_shouldReturnProviderValue.
@Test
public void getType_shouldReturnProviderValue() {
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 "mytype";
}
});
final Uri uri = Uri.parse("content://" + AUTHORITY + "/some/path");
assertThat(contentResolver.getType(uri)).isEqualTo("mytype");
}
use of org.robolectric.fakes.BaseCursor in project robolectric by robolectric.
the class ShadowContentResolverTest method query_shouldReturnSpecificCursorsForSpecificUris.
@Test
public void query_shouldReturnSpecificCursorsForSpecificUris() {
assertThat(shadowContentResolver.query(uri21, null, null, null, null)).isNull();
assertThat(shadowContentResolver.query(uri22, null, null, null, null)).isNull();
BaseCursor cursor21 = new BaseCursor();
BaseCursor cursor22 = new BaseCursor();
shadowContentResolver.setCursor(uri21, cursor21);
shadowContentResolver.setCursor(uri22, cursor22);
assertThat((BaseCursor) shadowContentResolver.query(uri21, null, null, null, null)).isSameInstanceAs(cursor21);
assertThat((BaseCursor) shadowContentResolver.query(uri22, null, null, null, null)).isSameInstanceAs(cursor22);
}
use of org.robolectric.fakes.BaseCursor 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 org.robolectric.fakes.BaseCursor 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;
}
}
Aggregations