@Test
  public void testSuccessTransaction() throws Exception {
    assertThat(shDatabase.isTransactionSuccess()).isFalse();
    database.beginTransaction();
    assertThat(shDatabase.isTransactionSuccess()).isFalse();
    database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");
    assertThat(shDatabase.isTransactionSuccess()).isFalse();
    database.setTransactionSuccessful();
    assertThat(shDatabase.isTransactionSuccess()).isTrue();
    database.endTransaction();
    assertThat(shDatabase.isTransactionSuccess()).isFalse();

    Cursor cursor = database.rawQuery("SELECT COUNT(*) FROM table_name", null);
    assertThat(cursor.moveToNext()).isTrue();
    assertThat(cursor.getInt(0)).isEqualTo(1);
  }
  @Test
  public void testFailureTransaction() throws Exception {
    assertThat(shDatabase.isTransactionSuccess()).isFalse();
    database.beginTransaction();
    assertThat(shDatabase.isTransactionSuccess()).isFalse();

    database.execSQL("INSERT INTO table_name (id, name) VALUES(1234, 'Chuck');");

    final String select = "SELECT COUNT(*) FROM table_name";

    Cursor cursor = database.rawQuery(select, null);
    assertThat(cursor.moveToNext()).isTrue();
    assertThat(cursor.getInt(0)).isEqualTo(1);
    cursor.close();

    assertThat(shDatabase.isTransactionSuccess()).isFalse();
    database.endTransaction();

    cursor = database.rawQuery(select, null);
    assertThat(cursor.moveToNext()).isTrue();
    assertThat(cursor.getInt(0)).isEqualTo(0);

    assertThat(shDatabase.isTransactionSuccess()).isFalse();
  }
  @Test
  public void shouldLockWhenEnabled() throws Exception {
    ShadowSQLiteDatabase shadowDB = shadowOf(database);

    // Test disabled locking
    shadowDB.setLockingEnabled(false);

    assertThat(database.isDbLockedByCurrentThread()).isTrue();
    shadowDB.lock();
    assertThat(database.isDbLockedByCurrentThread()).isTrue();
    shadowDB.unlock();
    assertThat(database.isDbLockedByCurrentThread()).isTrue();

    // Test enabled locking
    shadowDB.setLockingEnabled(true);
    assertThat(database.isDbLockedByCurrentThread()).isFalse();
    shadowDB.lock();
    assertThat(database.isDbLockedByCurrentThread()).isTrue();
    shadowDB.unlock();
    assertThat(database.isDbLockedByCurrentThread()).isFalse();
  }
 @Test(expected = android.database.SQLException.class)
 public void testInsertOrThrowWithSimulatedSQLException() {
   shDatabase.setThrowOnInsert(true);
   database.insertOrThrow("table_name", null, new ContentValues());
 }