Search in sources :

Example 1 with RawQuery

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);
}
Also used : NonNull(android.support.annotation.NonNull) RawQuery(com.pushtorefresh.storio.sqlite.queries.RawQuery) Cursor(android.database.Cursor) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 2 with RawQuery

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);
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) RawQuery(com.pushtorefresh.storio.sqlite.queries.RawQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 3 with RawQuery

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);
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) RawQuery(com.pushtorefresh.storio.sqlite.queries.RawQuery) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Aggregations

StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)3 RawQuery (com.pushtorefresh.storio.sqlite.queries.RawQuery)3 Test (org.junit.Test)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)2 SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)2 Cursor (android.database.Cursor)1 NonNull (android.support.annotation.NonNull)1