Search in sources :

Example 21 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method defaultRxSchedulerReturnsNullIfSpecifiedSchedulerNull.

@Test
public void defaultRxSchedulerReturnsNullIfSpecifiedSchedulerNull() {
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).defaultRxScheduler(null).build();
    assertThat(storIOContentResolver.defaultRxScheduler()).isNull();
}
Also used : StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 22 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method shouldUseCustomHandlerForContentObservers.

@Test
public void shouldUseCustomHandlerForContentObservers() {
    ContentResolver contentResolver = mock(ContentResolver.class);
    ArgumentCaptor<ContentObserver> observerArgumentCaptor = ArgumentCaptor.forClass(ContentObserver.class);
    doNothing().when(contentResolver).registerContentObserver(any(Uri.class), anyBoolean(), observerArgumentCaptor.capture());
    Handler handler = mock(Handler.class);
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(contentResolver).contentObserverHandler(handler).defaultRxScheduler(null).build();
    Disposable disposable = storIOContentResolver.observeChangesOfUri(mock(Uri.class), LATEST).subscribe();
    assertThat(observerArgumentCaptor.getAllValues()).hasSize(1);
    ContentObserver contentObserver = observerArgumentCaptor.getValue();
    Object actualHandler = ReflectionHelpers.getField(contentObserver, "mHandler");
    assertThat(actualHandler).isEqualTo(handler);
    disposable.dispose();
}
Also used : Disposable(io.reactivex.disposables.Disposable) Handler(android.os.Handler) Uri(android.net.Uri) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) ContentObserver(android.database.ContentObserver) Test(org.junit.Test)

Example 23 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method shouldReturnSameContentResolver.

@Test
public void shouldReturnSameContentResolver() {
    ContentResolver contentResolver = mock(ContentResolver.class);
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(contentResolver).build();
    assertThat(storIOContentResolver.lowLevel().contentResolver()).isSameAs(contentResolver);
}
Also used : StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 24 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method shouldThrowExceptionIfContentResolverReturnsNull.

@Test
public void shouldThrowExceptionIfContentResolverReturnsNull() {
    ContentResolver contentResolver = mock(ContentResolver.class);
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(contentResolver).build();
    Query query = Query.builder().uri(mock(Uri.class)).build();
    when(contentResolver.query(any(Uri.class), any(String[].class), anyString(), any(String[].class), anyString())).thenReturn(// Notice, we return null instead of Cursor
    null);
    try {
        storIOContentResolver.lowLevel().query(query);
    } catch (IllegalStateException expected) {
        assertThat(expected).hasMessage("Cursor returned by content provider is null");
    }
}
Also used : Query(com.pushtorefresh.storio3.contentresolver.queries.Query) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Uri(android.net.Uri) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 25 with StorIOContentResolver

use of com.pushtorefresh.storio3.contentresolver.StorIOContentResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method deprecatedInternalImplShouldReturnSentToConstructorTypeMapping.

@Test
public void deprecatedInternalImplShouldReturnSentToConstructorTypeMapping() throws NoSuchFieldException, IllegalAccessException {
    ContentResolver contentResolver = mock(ContentResolver.class);
    TypeMappingFinder typeMappingFinder = mock(TypeMappingFinder.class);
    TestDefaultStorIOContentResolver storIOContentResolver = new TestDefaultStorIOContentResolver(contentResolver, mock(Handler.class), typeMappingFinder);
    assertThat(storIOContentResolver.typeMappingFinder()).isSameAs(typeMappingFinder);
}
Also used : TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) Handler(android.os.Handler) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)31 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)23 Query (com.pushtorefresh.storio3.contentresolver.queries.Query)11 ContentResolver (android.content.ContentResolver)9 NonNull (android.support.annotation.NonNull)9 ContentValues (android.content.ContentValues)8 Cursor (android.database.Cursor)7 Uri (android.net.Uri)7 DeleteQuery (com.pushtorefresh.storio3.contentresolver.queries.DeleteQuery)6 TypeMappingFinder (com.pushtorefresh.storio3.TypeMappingFinder)5 InsertQuery (com.pushtorefresh.storio3.contentresolver.queries.InsertQuery)5 UpdateQuery (com.pushtorefresh.storio3.contentresolver.queries.UpdateQuery)5 DeleteResult (com.pushtorefresh.storio3.contentresolver.operations.delete.DeleteResult)4 PutResult (com.pushtorefresh.storio3.contentresolver.operations.put.PutResult)4 StorIOException (com.pushtorefresh.storio3.StorIOException)3 GetResolver (com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver)3 Handler (android.os.Handler)2 TypeMappingFinderImpl (com.pushtorefresh.storio3.internal.TypeMappingFinderImpl)2 Completable (io.reactivex.Completable)2 ContentObserver (android.database.ContentObserver)1