Search in sources :

Example 71 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 72 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 73 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)

Example 74 with SQLiteOpenHelper

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

the class DefaultStorIOSQLiteTest method defaultSchedulerReturnsNullIfSpecifiedSchedulerNull.

@Test
public void defaultSchedulerReturnsNullIfSpecifiedSchedulerNull() {
    StorIOSQLite storIOSQLite = DefaultStorIOSQLite.builder().sqliteOpenHelper(mock(SQLiteOpenHelper.class)).defaultScheduler(null).build();
    assertThat(storIOSQLite.defaultScheduler()).isNull();
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) StorIOSQLite(com.pushtorefresh.storio.sqlite.StorIOSQLite) Test(org.junit.Test)

Example 75 with SQLiteOpenHelper

use of android.database.sqlite.SQLiteOpenHelper in project zxing by zxing.

the class HistoryManager method clearHistory.

void clearHistory() {
    SQLiteOpenHelper helper = new DBHelper(activity);
    SQLiteDatabase db = null;
    try {
        db = helper.getWritableDatabase();
        db.delete(DBHelper.TABLE_NAME, null, null);
    } catch (SQLException sqle) {
        Log.w(TAG, sqle);
    } finally {
        close(null, db);
    }
}
Also used : SQLiteOpenHelper(android.database.sqlite.SQLiteOpenHelper) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException)

Aggregations

SQLiteOpenHelper (android.database.sqlite.SQLiteOpenHelper)95 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)79 Cursor (android.database.Cursor)47 Test (org.junit.Test)35 ContentValues (android.content.ContentValues)19 Context (android.content.Context)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 Result (com.google.zxing.Result)10 StorIOSQLite (com.pushtorefresh.storio.sqlite.StorIOSQLite)9 SQLException (android.database.SQLException)7 ArrayList (java.util.ArrayList)7 SharedPreferences (android.content.SharedPreferences)5 DateFormat (java.text.DateFormat)5 SQLiteDiskIOException (android.database.sqlite.SQLiteDiskIOException)4 SQLiteFullException (android.database.sqlite.SQLiteFullException)4 SQLiteQueryBuilder (android.database.sqlite.SQLiteQueryBuilder)4 Returns (org.mockito.internal.stubbing.answers.Returns)4 SQLiteException (android.database.sqlite.SQLiteException)3 DatabaseHelper (com.android.launcher3.LauncherProvider.DatabaseHelper)3 DBHelper (dev.sagar.smsblocker.tech.service.helper.DBHelper)3