use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method typeMappingShouldWorkWithSpecifiedTypeMappingFinder.
@Test
public void typeMappingShouldWorkWithSpecifiedTypeMappingFinder() {
TypeMappingFinder typeMappingFinder = new TypeMappingFinderImpl();
// noinspection unchecked
SQLiteTypeMapping<ClassEntity> typeMapping = SQLiteTypeMapping.builder().putResolver(mock(PutResolver.class)).getResolver(mock(GetResolver.class)).deleteResolver(mock(DeleteResolver.class)).build();
DefaultStorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).typeMappingFinder(typeMappingFinder).addTypeMapping(ClassEntity.class, typeMapping).build();
assertThat(storIOSQLite.lowLevel().typeMapping(ClassEntity.class)).isEqualTo(typeMapping);
}
use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.
the class DbModule method provideStorIOSQLite.
// We suggest to keep one instance of StorIO (SQLite or ContentResolver)
// It's thread safe and so on, so just share it.
// But if you need you can have multiple instances of StorIO
// (SQLite or ContentResolver) with different settings such as type mapping, logging and so on.
// But keep in mind that different instances of StorIOSQLite won't share notifications!
@Provides
@NonNull
@Singleton
public StorIOSQLite provideStorIOSQLite(@NonNull SQLiteOpenHelper sqLiteOpenHelper) {
final CarStorIOSQLitePutResolver carStorIOSQLitePutResolver = new CarStorIOSQLitePutResolver();
final CarStorIOSQLiteGetResolver carStorIOSQLiteGetResolver = new CarStorIOSQLiteGetResolver();
final PersonStorIOSQLitePutResolver personStorIOSQLitePutResolver = new PersonStorIOSQLitePutResolver();
final PersonStorIOSQLiteGetResolver personStorIOSQLiteGetResolver = new PersonStorIOSQLiteGetResolver();
final CarPersonRelationPutResolver carPersonRelationPutResolver = new CarPersonRelationPutResolver();
return DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).addTypeMapping(Tweet.class, new TweetSQLiteTypeMapping()).addTypeMapping(User.class, new UserSQLiteTypeMapping()).addTypeMapping(TweetWithUser.class, SQLiteTypeMapping.<TweetWithUser>builder().putResolver(new TweetWithUserPutResolver()).getResolver(new TweetWithUserGetResolver()).deleteResolver(new TweetWithUserDeleteResolver()).build()).addTypeMapping(Person.class, SQLiteTypeMapping.<Person>builder().putResolver(new PersonRelationsPutResolver(carStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new PersonRelationsGetResolver(carStorIOSQLiteGetResolver)).deleteResolver(new PersonRelationsDeleteResolver()).build()).addTypeMapping(Car.class, SQLiteTypeMapping.<Car>builder().putResolver(new CarRelationsPutResolver(personStorIOSQLitePutResolver, carPersonRelationPutResolver)).getResolver(new CarRelationsGetResolver(personStorIOSQLiteGetResolver)).deleteResolver(new CarRelationsDeleteResolver()).build()).build();
}
use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver 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");
}
}
use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.
the class DefaultGetResolverTest method query.
@Test
public void query() {
final StorIOContentResolver storIOContentResolver = mock(StorIOContentResolver.class);
final StorIOContentResolver.LowLevel lowLevel = mock(StorIOContentResolver.LowLevel.class);
final Query query = Query.builder().uri(mock(Uri.class)).build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOContentResolver.lowLevel()).thenReturn(lowLevel);
when(lowLevel.query(query)).thenReturn(expectedCursor);
final GetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull StorIOContentResolver storIOContentResolver, @NonNull Cursor cursor) {
assertThat(cursor).isSameAs(expectedCursor);
return new TestItem();
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOContentResolver, query);
// only one request should occur
verify(lowLevel, times(1)).query(any(Query.class));
// and this request should be equals to original
verify(lowLevel, times(1)).query(query);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio3.contentresolver.operations.get.GetResolver in project storio by pushtorefresh.
the class PreparedGetCursorTest method shouldWrapExceptionIntoStorIOExceptionForSingle.
@Test
public void shouldWrapExceptionIntoStorIOExceptionForSingle() {
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"));
final TestObserver<Cursor> testObserver = new TestObserver<Cursor>();
new PreparedGetCursor.Builder(storIOSQLite).withQuery(Query.builder().table("test_table").build()).withGetResolver(getResolver).prepare().asRxSingle().subscribe(testObserver);
testObserver.awaitTerminalEvent(60, SECONDS);
testObserver.assertError(StorIOException.class);
StorIOException storIOException = (StorIOException) testObserver.errors().get(0);
IllegalStateException cause = (IllegalStateException) storIOException.getCause();
assertThat(cause).hasMessage("test exception");
}
Aggregations