use of com.pushtorefresh.storio.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.Internal internal = mock(StorIOSQLite.Internal.class);
final RawQuery rawQuery = RawQuery.builder().query("test sql").build();
final Cursor expectedCursor = mock(Cursor.class);
when(storIOSQLite.lowLevel()).thenReturn(internal);
when(internal.rawQuery(rawQuery)).thenReturn(expectedCursor);
final DefaultGetResolver<TestItem> defaultGetResolver = new DefaultGetResolver<TestItem>() {
@NonNull
@Override
public TestItem mapFromCursor(@NonNull Cursor cursor) {
return mock(TestItem.class);
}
};
final Cursor actualCursor = defaultGetResolver.performGet(storIOSQLite, rawQuery);
// only one request should occur
verify(internal, times(1)).rawQuery(any(RawQuery.class));
// and this request should be equals to original
verify(internal, times(1)).rawQuery(rawQuery);
assertThat(actualCursor).isSameAs(expectedCursor);
}
use of com.pushtorefresh.storio.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassSQLWithArgsToExecSQL.
@Test
public void shouldPassSQLWithArgsToExecSQL() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
when(sqLiteOpenHelper.getWritableDatabase()).thenReturn(sqLiteDatabase);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
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.storio.sqlite.queries.RawQuery in project storio by pushtorefresh.
the class DefaultStorIOSQLiteTest method shouldPassSQLWithoutArgsToExecSQL.
@Test
public void shouldPassSQLWithoutArgsToExecSQL() {
SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
SQLiteDatabase sqLiteDatabase = mock(SQLiteDatabase.class);
when(sqLiteOpenHelper.getWritableDatabase()).thenReturn(sqLiteDatabase);
StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
RawQuery rawQuery = RawQuery.builder().query("DROP TABLE IF EXISTS someTable").build();
storIOSQLite.lowLevel().executeSQL(rawQuery);
verify(sqLiteOpenHelper).getWritableDatabase();
verify(sqLiteDatabase).execSQL(eq(rawQuery.query()));
verifyNoMoreInteractions(sqLiteOpenHelper, sqLiteDatabase);
}
Aggregations