Search in sources :

Example 1 with BaseCursor

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

Example 2 with BaseCursor

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");
}
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 3 with BaseCursor

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

Example 4 with BaseCursor

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

Example 5 with BaseCursor

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

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