Search in sources :

Example 6 with GetResolver

use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.

the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForBlocking.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForBlocking() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    // noinspection unchecked
    final GetResolver<Cursor> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    try {
        new PreparedGetCursor.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").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.storio3.sqlite.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 7 with GetResolver

use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.

the class PreparedGetNumberOfResultsTest method shouldWrapExceptionIntoStorIOExceptionForSingle.

@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    // noinspection unchecked
    final GetResolver<Integer> getResolver = mock(GetResolver.class);
    when(getResolver.performGet(eq(storIOSQLite), any(Query.class))).thenThrow(new IllegalStateException("test exception"));
    final TestObserver<Integer> testObserver = new TestObserver<Integer>();
    new PreparedGetNumberOfResults.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testObserver);
    testObserver.awaitTerminalEvent(60, SECONDS);
    testObserver.assertError(StorIOException.class);
    assertThat(testObserver.errorCount()).isEqualTo(1);
    StorIOException storIOException = (StorIOException) testObserver.errors().get(0);
    IllegalStateException cause = (IllegalStateException) storIOException.getCause();
    assertThat(cause).hasMessage("test exception");
}
Also used : Query(com.pushtorefresh.storio3.sqlite.queries.Query) StorIOException(com.pushtorefresh.storio3.StorIOException) StorIOSQLite(com.pushtorefresh.storio3.sqlite.StorIOSQLite) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Example 8 with GetResolver

use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.

the class DefaultStorIOContentResolverTest method typeMappingShouldWorkWithSpecifiedTypeMappingFinder.

@Test
public void typeMappingShouldWorkWithSpecifiedTypeMappingFinder() {
    TypeMappingFinder typeMappingFinder = new TypeMappingFinderImpl();
    // 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)).typeMappingFinder(typeMappingFinder).addTypeMapping(ClassEntity.class, typeMapping).build();
    assertThat(storIOContentResolver.lowLevel().typeMapping(ClassEntity.class)).isEqualTo(typeMapping);
}
Also used : TypeMappingFinderImpl(com.pushtorefresh.storio3.internal.TypeMappingFinderImpl) TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) GetResolver(com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) Test(org.junit.Test)

Example 9 with GetResolver

use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver 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.storio3.internal.TypeMappingFinderImpl) TypeMappingFinder(com.pushtorefresh.storio3.TypeMappingFinder) GetResolver(com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Example 10 with GetResolver

use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver 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.storio3.contentresolver.operations.get.GetResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) StorIOContentResolver(com.pushtorefresh.storio3.contentresolver.StorIOContentResolver) ContentResolver(android.content.ContentResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 StorIOException (com.pushtorefresh.storio3.StorIOException)9 StorIOContentResolver (com.pushtorefresh.storio3.contentresolver.StorIOContentResolver)7 StorIOSQLite (com.pushtorefresh.storio3.sqlite.StorIOSQLite)6 Query (com.pushtorefresh.storio3.sqlite.queries.Query)6 Cursor (android.database.Cursor)4 Query (com.pushtorefresh.storio3.contentresolver.queries.Query)4 TypeMappingFinder (com.pushtorefresh.storio3.TypeMappingFinder)3 GetResolver (com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver)3 TypeMappingFinderImpl (com.pushtorefresh.storio3.internal.TypeMappingFinderImpl)3 TestObserver (io.reactivex.observers.TestObserver)3 TestSubscriber (io.reactivex.subscribers.TestSubscriber)3 ContentResolver (android.content.ContentResolver)2 Uri (android.net.Uri)2 NonNull (android.support.annotation.NonNull)2 BackpressureStrategy (io.reactivex.BackpressureStrategy)2 Tweet (com.pushtorefresh.storio3.sample.db.entities.Tweet)1 TweetSQLiteTypeMapping (com.pushtorefresh.storio3.sample.db.entities.TweetSQLiteTypeMapping)1 TweetWithUser (com.pushtorefresh.storio3.sample.db.entities.TweetWithUser)1 UserSQLiteTypeMapping (com.pushtorefresh.storio3.sample.db.entities.UserSQLiteTypeMapping)1