Search in sources :

Example 26 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper 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 27 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method notifyAboutChangesShouldNotAcceptNullAsChanges.

@Test
public void notifyAboutChangesShouldNotAcceptNullAsChanges() {
    SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
    StorIOSQLite.LowLevel lowLevel = storIOSQLite.lowLevel();
    assertThat(lowLevel).isNotNull();
    try {
        //noinspection ConstantConditions
        lowLevel.notifyAboutChanges(null);
        failBecauseExceptionWasNotThrown(NullPointerException.class);
    } catch (NullPointerException expected) {
        assertThat(expected).hasMessage("Changes can not be null");
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 28 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method shouldCloseSQLiteOpenHelper.

@Test
public void shouldCloseSQLiteOpenHelper() throws IOException {
    SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
    // Should not call close before explicit call to close
    verify(sqLiteOpenHelper, times(0)).close();
    storIOSQLite.close();
    // Should call close on SQLiteOpenHelper
    verify(sqLiteOpenHelper).close();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 29 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper 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)

Example 30 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project storio by pushtorefresh.

the class DefaultStorIOSQLiteTest method observeChangesAndNotifyAboutChangesShouldWorkCorrectly.

@Test
public void observeChangesAndNotifyAboutChangesShouldWorkCorrectly() {
    SQLiteOpenHelper sqLiteOpenHelper = mock(SQLiteOpenHelper.class);
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(sqLiteOpenHelper).build();
    TestSubscriber<Changes> testSubscriber = new TestSubscriber<Changes>();
    storIOSQLite.observeChanges().subscribe(testSubscriber);
    testSubscriber.assertNoValues();
    Changes changes = Changes.newInstance("test_table");
    storIOSQLite.lowLevel().notifyAboutChanges(changes);
    testSubscriber.assertValue(changes);
    testSubscriber.assertNoErrors();
    testSubscriber.unsubscribe();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) Changes(com.pushtorefresh.storio.sqlite.Changes) TestSubscriber(rx.observers.TestSubscriber) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Aggregations

SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)46 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)36 Cursor (android.database.Cursor)21 Test (org.junit.Test)14 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)9 ContentValues (android.content.ContentValues)7 Result (com.google.zxing.Result)6 SQLException (android.database.SQLException)5 SharedPreferences (android.content.SharedPreferences)3 DateFormat (java.text.DateFormat)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 SQLiteException (android.database.sqlite.SQLiteException)2 Changes (com.pushtorefresh.storio.sqlite.Changes)2 RawQuery (com.pushtorefresh.storio.sqlite.queries.RawQuery)2 Date (java.util.Date)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 TypeMappingFinder (com.pushtorefresh.storio.TypeMappingFinder)1 InsertQuery (com.pushtorefresh.storio.sqlite.queries.InsertQuery)1 Serializable (java.io.Serializable)1