Search in sources :

Example 11 with StorIOContentResolver

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

the class PreparedGetCursorTest method shouldUseStandardGetResolverWithoutExplicitlyPassed.

@Test
public void shouldUseStandardGetResolverWithoutExplicitlyPassed() {
    StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
    StorIOContentResolver.LowLevel lowLevel = mock(StorIOContentResolver.LowLevel.class);
    when(storIOContentResolver.lowLevel()).thenReturn(lowLevel);
    Query query = Query.builder().uri(mock(Uri.class)).build();
    new PreparedGetCursor.Builder(storIOContentResolver).withQuery(query).prepare().executeAsBlocking();
    verify(storIOContentResolver).lowLevel();
    verify(lowLevel).query(query);
    verifyNoMoreInteractions(storIOContentResolver, lowLevel);
}
Also used : Query(com.pushtorefresh.storio.contentresolver.queries.Query) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 12 with StorIOContentResolver

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

the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForBlocking.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForBlocking() {
    final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
    //noinspection unchecked
    final GetResolver<Integer> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOContentResolver), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    try {
        new PreparedGetNumberOfResults.Builder(storIOContentResolver).withQuery(Query.builder().uri(mock(Uri.class)).build()).withGetResolver(getResolver).prepare().executeAsBlocking();
        failBecauseExceptionWasNotThrown(StorIOException.class);
    } catch (StorIOException expected) {
        IllegalStateException cause = (IllegalStateException) expected.getCause();
        assertThat(cause).hasMessage("test exception");
    }
}
Also used : Query(com.pushtorefresh.storio.contentresolver.queries.Query) StorIOException(com.pushtorefresh.storio.StorIOException) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 13 with StorIOContentResolver

use of com.pushtorefresh.storio.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.storio.TypeMappingFinder) Handler(android.os.Handler) ContentResolver(android.content.ContentResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 14 with StorIOContentResolver

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

the class DefaultStorIOContentResolverTest method typeMappingShouldWorkWithoutSpecifiedTypeMappingFinder.

@Test
public void typeMappingShouldWorkWithoutSpecifiedTypeMappingFinder() {
    //noinspection unchecked
    ContentResolverTypeMapping<ClassEntity> typeMapping = ContentResolverTypeMapping.builder().putResolver(mock(PutResolver.class)).getResolver(mock(GetResolver.class)).deleteResolver(mock(DeleteResolver.class)).build();
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).addTypeMapping(ClassEntity.class, typeMapping).build();
    assertThat(storIOContentResolver.lowLevel().typeMapping(ClassEntity.class)).isEqualTo(typeMapping);
}
Also used : GetResolver(com.pushtorefresh.storio.contentresolver.operations.get.GetResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 15 with StorIOContentResolver

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

the class DefaultStorIOContentResolverTest method typeMappingShouldWorkForMultipleTypes.

@Test
public void typeMappingShouldWorkForMultipleTypes() {
    class AnotherEntity {
    }
    TypeMappingFinder typeMappingFinder = new TypeMappingFinderImpl();
    //noinspection unchecked
    ContentResolverTypeMapping<ClassEntity> typeMapping = ContentResolverTypeMapping.builder().putResolver(mock(PutResolver.class)).getResolver(mock(GetResolver.class)).deleteResolver(mock(DeleteResolver.class)).build();
    //noinspection unchecked
    ContentResolverTypeMapping<AnotherEntity> anotherMapping = ContentResolverTypeMapping.builder().putResolver(mock(PutResolver.class)).getResolver(mock(GetResolver.class)).deleteResolver(mock(DeleteResolver.class)).build();
    StorIOContentResolver storIOContentResolver = DefaultStorIOContentResolver.builder().contentResolver(mock(ContentResolver.class)).typeMappingFinder(typeMappingFinder).addTypeMapping(ClassEntity.class, typeMapping).addTypeMapping(AnotherEntity.class, anotherMapping).build();
    assertThat(storIOContentResolver.lowLevel().typeMapping(ClassEntity.class)).isEqualTo(typeMapping);
    assertThat(storIOContentResolver.lowLevel().typeMapping(AnotherEntity.class)).isEqualTo(anotherMapping);
}
Also used : TypeMappingFinderImpl(com.pushtorefresh.storio.internal.TypeMappingFinderImpl) TypeMappingFinder(com.pushtorefresh.storio.TypeMappingFinder) GetResolver(com.pushtorefresh.storio.contentresolver.operations.get.GetResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) StorIOContentResolver(com.pushtorefresh.storio.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Aggregations

StorIOContentResolver (com.pushtorefresh.storio.contentresolver.StorIOContentResolver)23 Test (org.junit.Test)20 Query (com.pushtorefresh.storio.contentresolver.queries.Query)11 NonNull (android.support.annotation.NonNull)9 ContentResolver (android.content.ContentResolver)8 Cursor (android.database.Cursor)6 Uri (android.net.Uri)6 ContentValues (android.content.ContentValues)5 StorIOException (com.pushtorefresh.storio.StorIOException)5 InsertQuery (com.pushtorefresh.storio.contentresolver.queries.InsertQuery)5 UpdateQuery (com.pushtorefresh.storio.contentresolver.queries.UpdateQuery)5 TypeMappingFinder (com.pushtorefresh.storio.TypeMappingFinder)4 GetResolver (com.pushtorefresh.storio.contentresolver.operations.get.GetResolver)3 WorkerThread (android.support.annotation.WorkerThread)2 ContentResolverTypeMapping (com.pushtorefresh.storio.contentresolver.ContentResolverTypeMapping)2 TypeMappingFinderImpl (com.pushtorefresh.storio.internal.TypeMappingFinderImpl)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 HashMap (java.util.HashMap)2 TestSubscriber (rx.observers.TestSubscriber)2 Handler (android.os.Handler)1