@Test
public void onUpgradeFromV16WhenCustomOrderIdColumnIsMissing() {

    final int oldVersion = 16;
    final int newVersion = DatabaseHelper.DATABASE_VERSION;
    final TableDefaultsCustomizer customizer = mock(TableDefaultsCustomizer.class);
    final Cursor cursor = mock(Cursor.class);
    final String pragmaTableInfo = "PRAGMA table_info(" + mPaymentMethodsTable.getTableName() + ")";
    final int columnNameIndex = 0;
    when(mSQLiteDatabase.rawQuery(pragmaTableInfo, null)).thenReturn(cursor);
    when(cursor.moveToFirst()).thenReturn(true);
    when(cursor.getColumnIndex("name")).thenReturn(columnNameIndex);
    when(cursor.getString(columnNameIndex)).thenReturn("id", "method", "drive_sync_id", "drive_is_synced", "drive_marked_for_deletion", "last_local_modification_time");
    when(cursor.moveToNext()).thenReturn(true, true, true, true, true, false);
    mPaymentMethodsTable.onUpgrade(mSQLiteDatabase, oldVersion, newVersion, customizer);
    verify(mSQLiteDatabase, atLeastOnce()).execSQL(mSqlCaptor.capture());
    verify(customizer, never()).insertPaymentMethodDefaults(mPaymentMethodsTable);
    assertEquals(mSqlCaptor.getAllValues().get(0), "ALTER TABLE " + mPaymentMethodsTable.getTableName() + " ADD COLUMN custom_order_id INTEGER DEFAULT 0");
    assertEquals(mSqlCaptor.getAllValues().get(1), "UPDATE " + mPaymentMethodsTable.getTableName() + " SET custom_order_id = ROWID");
}