SqlDatabaseSupplier extends SQLiteOpenHelper implements Supplier<Result<SQLiteDatabase>> { @NonNull @Override public final synchronized Result<SQLiteDatabase> get() { try { return absentIfNull(getWritableDatabase()); } catch (final SQLException e) { return failure(e); } } SqlDatabaseSupplier(@NonNull final Context context, @NonNull final String path,
      @Nullable final CursorFactory factory, final int version); @NonNull @Override final synchronized Result<SQLiteDatabase> get();  }
@Test public void shouldSupplyDatabase() throws Throwable { final SqlDatabaseSupplier sqlDatabaseSupplier = new SqlDatabaseSupplier( application.getApplicationContext(), DATABASE_NAME, null, 1) { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) {} @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int i, final int i1) {} }; assertThat(sqlDatabaseSupplier.get().get(), instanceOf(SQLiteDatabase.class)); }
@Test public void shouldSupplyFailureIfFailingOnCreate() throws Throwable { final SqlDatabaseSupplier sqlDatabaseSupplier = new SqlDatabaseSupplier( application.getApplicationContext(), DATABASE_NAME, null, 1) { @Override public void onCreate(final SQLiteDatabase sqLiteDatabase) { throw new SQLException(); } @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int i, final int i1) {} }; assertThat(sqlDatabaseSupplier.get().failed(), is(true)); }