HaloDataLite extends SQLiteOpenHelper implements Corruptible { @Api(2.0) public void transaction(@NonNull HaloDataLiteTransaction transaction) throws HaloStorageGeneralException { SQLiteDatabase database = getDatabase(); database.beginTransaction(); try { transaction.onTransaction(database); database.setTransactionSuccessful(); } catch (Exception e) { throw new HaloStorageGeneralException("Database error: " + e.getMessage(), e); } finally { database.endTransaction(); } } 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 thatHandleTransactionCallback() throws HaloStorageGeneralException { HaloDataLite.HaloDataLiteTransaction transactionCallback = givenATransactionCallback(mCallbackFlag); mHaloDatabase.transaction(transactionCallback); assertThat(mCallbackFlag.isFlagged()).isTrue(); }
@Test public void thatHandleTransactionException() throws HaloStorageGeneralException { HaloDataLite.HaloDataLiteTransaction transactionCallback = givenATransactionCallbackException(mCallbackFlag,mHaloDatabase); try { mHaloDatabase.transaction(transactionCallback); } catch (HaloStorageGeneralException haloStorageException){ mCallbackFlag.flagExecuted(); } assertThat(mCallbackFlag.isFlagged()).isTrue(); }