### Question:
StoreSchemaDefinition implements LockableDatabase.SchemaDefinition { @Override public void doDbUpgrade(final SQLiteDatabase db) { try { upgradeDatabase(db); } catch (Exception e) { if (BuildConfig.DEBUG) { throw new Error("Exception while upgrading database", e); } Timber.e(e, "Exception while upgrading database. Resetting the DB to v0"); db.setVersion(0); upgradeDatabase(db); } } StoreSchemaDefinition(LocalStore localStore); @Override int getVersion(); @Override void doDbUpgrade(final SQLiteDatabase db);  }### Answer:
@Test public void doDbUpgrade_withBadDatabase_shouldThrowInDebugBuild() { if (BuildConfig.DEBUG) { SQLiteDatabase database = SQLiteDatabase.create(null); database.setVersion(29); try { storeSchemaDefinition.doDbUpgrade(database); fail("Expected Error"); } catch (Error e) { assertEquals("Exception while upgrading database", e.getMessage()); } } }
@Test public void doDbUpgrade_withV29() { SQLiteDatabase database = createV29Database(); insertMessageWithSubject(database, "Test Email"); storeSchemaDefinition.doDbUpgrade(database); assertMessageWithSubjectExists(database, "Test Email"); }
@Test public void doDbUpgrade_fromV29_shouldResultInSameTables() { SQLiteDatabase newDatabase = createNewDatabase(); SQLiteDatabase upgradedDatabase = createV29Database(); storeSchemaDefinition.doDbUpgrade(upgradedDatabase); assertDatabaseTablesEquals(newDatabase, upgradedDatabase); }
@Test public void doDbUpgrade_fromV29_shouldResultInSameTriggers() { SQLiteDatabase newDatabase = createNewDatabase(); SQLiteDatabase upgradedDatabase = createV29Database(); storeSchemaDefinition.doDbUpgrade(upgradedDatabase); assertDatabaseTriggersEquals(newDatabase, upgradedDatabase); }
@Test public void doDbUpgrade_fromV29_shouldResultInSameIndexes() { SQLiteDatabase newDatabase = createNewDatabase(); SQLiteDatabase upgradedDatabase = createV29Database(); storeSchemaDefinition.doDbUpgrade(upgradedDatabase); assertDatabaseIndexesEquals(newDatabase, upgradedDatabase); }