TripDatabaseAdapter implements DatabaseAdapter<Trip> { @Override @NonNull public Trip read(@NonNull Cursor cursor) { final int idIndex = cursor.getColumnIndex(CategoriesTable.COLUMN_ID); final int uuidIndex = cursor.getColumnIndex(CategoriesTable.COLUMN_UUID); final int nameIndex = cursor.getColumnIndex(TripsTable.COLUMN_NAME); final int fromIndex = cursor.getColumnIndex(TripsTable.COLUMN_FROM); final int toIndex = cursor.getColumnIndex(TripsTable.COLUMN_TO); final int fromTimeZoneIndex = cursor.getColumnIndex(TripsTable.COLUMN_FROM_TIMEZONE); final int toTimeZoneIndex = cursor.getColumnIndex(TripsTable.COLUMN_TO_TIMEZONE); final int commentIndex = cursor.getColumnIndex(TripsTable.COLUMN_COMMENT); final int costCenterIndex = cursor.getColumnIndex(TripsTable.COLUMN_COST_CENTER); final int defaultCurrencyIndex = cursor.getColumnIndex(TripsTable.COLUMN_DEFAULT_CURRENCY); final int nameHiddenFromAutoCompleteIndex = cursor.getColumnIndex(TripsTable.COLUMN_NAME_HIDDEN_AUTO_COMPLETE); final int commentHiddenFromAutoCompleteIndex = cursor.getColumnIndex(TripsTable.COLUMN_COMMENT_HIDDEN_AUTO_COMPLETE); final int costCenterHiddenFromAutoCompleteIndex = cursor.getColumnIndex(TripsTable.COLUMN_COSTCENTER_HIDDEN_AUTO_COMPLETE); final int id = cursor.getInt(idIndex); final UUID uuid = UUID.fromString(cursor.getString(uuidIndex)); final String name = cursor.getString(nameIndex); final long from = cursor.getLong(fromIndex); final long to = cursor.getLong(toIndex); final String fromTimeZone = cursor.getString(fromTimeZoneIndex); final String toTimeZone = cursor.getString(toTimeZoneIndex); final String comment = cursor.getString(commentIndex); final String costCenter = cursor.getString(costCenterIndex); final String defaultCurrency = cursor.getString(defaultCurrencyIndex); final boolean isNameHiddenFromAutoComplete = cursor.getInt(nameHiddenFromAutoCompleteIndex) > 0; final boolean isCommentHiddenFromAutoComplete = cursor.getInt(commentHiddenFromAutoCompleteIndex) > 0; final boolean isCostCenterHiddenFromAutoComplete = cursor.getInt(costCenterHiddenFromAutoCompleteIndex) > 0; final SyncState syncState = syncStateAdapter.read(cursor); return new TripBuilderFactory() .setId(id) .setUuid(uuid) .setDirectory(storageManager.mkdir(name)) .setStartDate(from) .setEndDate(to) .setStartTimeZone(fromTimeZone) .setEndTimeZone(toTimeZone) .setComment(comment) .setCostCenter(costCenter) .setDefaultCurrency(defaultCurrency, preferences.get(UserPreference.General.DefaultCurrency)) .setNameHiddenFromAutoComplete(isNameHiddenFromAutoComplete) .setCommentHiddenFromAutoComplete(isCommentHiddenFromAutoComplete) .setCostCenterHiddenFromAutoComplete(isCostCenterHiddenFromAutoComplete) .setSyncState(syncState) .build(); } TripDatabaseAdapter(@NonNull StorageManager storageManager, @NonNull UserPreferenceManager preferences, @NonNull SyncStateAdapter syncStateAdapter); @Override @NonNull Trip read(@NonNull Cursor cursor); @Override @NonNull ContentValues write(@NonNull Trip trip, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @Override @NonNull Trip build(@NonNull Trip trip, int primaryKey, @NonNull UUID uuid, @NonNull DatabaseOperationMetadata databaseOperationMetadata);  }
@Test public void read() throws Exception { final Trip trip = new TripBuilderFactory() .setId(ID) .setUuid(TRIP_UUID) .setDirectory(mStorageManager.getFile(NAME)) .setStartDate(START_DATE) .setEndDate(END_DATE) .setStartTimeZone(START_TIMEZONE) .setEndTimeZone(END_TIMEZONE) .setComment(COMMENT) .setCostCenter(COST_CENTER) .setDefaultCurrency(CURRENCY_CODE, mPreferences.get(UserPreference.General.DefaultCurrency)) .setSyncState(mSyncState) .setNameHiddenFromAutoComplete(NAME_HIDDEN_FROM_AUTO_COMPLETE) .setCommentHiddenFromAutoComplete(COMMENT_HIDDEN_FROM_AUTO_COMPLETE) .setCostCenterHiddenFromAutoComplete(COST_CENTER_HIDDEN_FROM_AUTO_COMPLETE) .build(); assertEquals(trip, mTripDatabaseAdapter.read(mCursor)); }