use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class DefaultGetResolverTest method rawQuery.
@Test
public void rawQuery() {
final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
final StorIOSQLite.LowLevel lowLevel = mock(StorIOSQLite.LowLevel.class);
final RawQuery rawQuery = RawQuery.builder().query("test sql").build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOSQLite.lowLevel()).thenReturn(lowLevel);
when(lowLevel.rawQuery(rawQuery)).thenReturn(expectedCursor);
final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull StorIOSQLite storIOSQLite, @NonNull Cursor cursor) {
return mock(TestItem.class);
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, rawQuery);
// only one request should occur
verify(lowLevel, times(1)).rawQuery(any(RawQuery.class));
// and this request should be equals to original
verify(lowLevel, times(1)).rawQuery(rawQuery);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class GetNumberOfResultsObserveChangesTest method repeatsOperationWithRawQueryByChangeOfTag.
@Test
public void repeatsOperationWithRawQueryByChangeOfTag() {
putUserBlocking();
PreparedGetNumberOfResults operation = storIOSQLite.get().numberOfResults().withQuery(rawQuery).prepare();
verifyChangesReceived(operation, tagChanges, 1);
}
use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassSQLWithArgsToExecSQL.
@Test
public void shouldPassSQLWithArgsToExecSQL() {
RawQuery rawQuery = RawQuery.builder().query("DROP TABLE users").args("arg1", "arg2").build();
storIOSQLite.lowLevel().executeSQL(rawQuery);
verify(sqLiteOpenHelper).getWritableDatabase();
verify(sqLiteDatabase).execSQL(eq(rawQuery.query()), eq(new String[] { "arg1", "arg2" }));
verifyNoMoreInteractions(sqLiteOpenHelper, sqLiteDatabase);
}
use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class GetNumberOfResultsObserveChangesTest method repeatsOperationWithRawQueryByChangeOfTable.
@Test
public void repeatsOperationWithRawQueryByChangeOfTable() {
putUserBlocking();
PreparedGetNumberOfResults operation = storIOSQLite.get().numberOfResults().withQuery(rawQuery).prepare();
verifyChangesReceived(operation, tableChanges, 1);
}
use of com.pushtorefresh.storio3.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class ExecSQLTest method shouldReturnQueryInGetData.
@Test
public void shouldReturnQueryInGetData() {
final RawQuery query = RawQuery.builder().query(// we don't want to really delete table
"DROP TABLE IF EXISTS no_such_table").build();
final PreparedExecuteSQL operation = storIOSQLite.executeSQL().withQuery(query).prepare();
assertThat(operation.getData()).isEqualTo(query);
}
Aggregations