Search in sources :

Example 6 with BaseCursor

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;
    }
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) IContentProvider(android.content.IContentProvider) ContentProvider(android.content.ContentProvider) Implementation(org.robolectric.annotation.Implementation)

Example 7 with BaseCursor

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);
}
Also used : ContentValues(android.content.ContentValues) BaseCursor(org.robolectric.fakes.BaseCursor) ContentProvider(android.content.ContentProvider) Cursor(android.database.Cursor) MatrixCursor(android.database.MatrixCursor) BaseCursor(org.robolectric.fakes.BaseCursor) Uri(android.net.Uri) Test(org.junit.Test)

Example 8 with BaseCursor

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);
}
Also used : BaseCursor(org.robolectric.fakes.BaseCursor) Test(org.junit.Test)

Aggregations

BaseCursor (org.robolectric.fakes.BaseCursor)8 ContentProvider (android.content.ContentProvider)5 Test (org.junit.Test)5 IContentProvider (android.content.IContentProvider)3 Implementation (org.robolectric.annotation.Implementation)3 ContentValues (android.content.ContentValues)2 Cursor (android.database.Cursor)2 MatrixCursor (android.database.MatrixCursor)2 Uri (android.net.Uri)2 CancellationSignal (android.os.CancellationSignal)1