HaloDataLite extends SQLiteOpenHelper implements Corruptible { @Api(2.0) public synchronized SQLiteDatabase getDatabase() { if (mDatabase == null) { mDatabase = getWritableDatabase(); } return mDatabase; } private  HaloDataLite(@NonNull Context context, @NonNull String name, int version, @NonNull HaloDatabaseVersionManager manager, @NonNull HaloDatabaseErrorHandler handler); @Api(2.0) static Builder builder(Context context); @Override void onCreate(@NonNull SQLiteDatabase db); @Override void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion); @Api(2.0) synchronized SQLiteDatabase getDatabase(); @Api(2.0) void ensureInitialized(); @Override void onCorrupted(); @Api(1.0) void deleteDatabase(); @Api(1.3) void attachDatabase(@NonNull String databaseName, @NonNull String aliasName); @Api(1.3) void detachDatabase(@NonNull String aliasName); @Api(2.0) void transaction(@NonNull HaloDataLiteTransaction transaction);  }
@Test public void thatCanGetDatabaseSQL(){ assertThat(mHaloDatabase.getDatabase().getVersion()).isEqualTo(3); assertThat(mHaloDatabase.getReadableDatabase().getVersion()).isEqualTo(3); assertThat(mHaloDatabase.getWritableDatabase().getVersion()).isEqualTo(3); }
@Test public void thatCorruptionCallbackIsHandled(){ HaloDatabaseErrorHandler errorHandler = new HaloDatabaseErrorHandler(); Corruptible corruptible = new Corruptible() { @Override public void onCorrupted() { mCallbackFlag.flagExecuted(); } }; errorHandler.setCorruptible(corruptible); errorHandler.onCorruption(mHaloDatabase.getDatabase()); assertThat(mCallbackFlag.isFlagged()).isTrue(); }