TripDatabaseAdapter implements DatabaseAdapter<Trip> { @Override @NonNull public ContentValues write(@NonNull Trip trip, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { final ContentValues values = new ContentValues(); values.put(TripsTable.COLUMN_NAME, trip.getName()); values.put(TripsTable.COLUMN_FROM, trip.getStartDate().getTime()); values.put(TripsTable.COLUMN_TO, trip.getEndDate().getTime()); values.put(TripsTable.COLUMN_FROM_TIMEZONE, trip.getStartTimeZone().getID()); values.put(TripsTable.COLUMN_TO_TIMEZONE, trip.getEndTimeZone().getID()); values.put(TripsTable.COLUMN_COMMENT, trip.getComment()); values.put(TripsTable.COLUMN_COST_CENTER, trip.getCostCenter()); values.put(TripsTable.COLUMN_DEFAULT_CURRENCY, trip.getDefaultCurrencyCode()); values.put(TripsTable.COLUMN_UUID, trip.getUuid().toString()); values.put(TripsTable.COLUMN_NAME_HIDDEN_AUTO_COMPLETE, trip.getAutoCompleteMetadata().isNameHiddenFromAutoComplete()); values.put(TripsTable.COLUMN_COMMENT_HIDDEN_AUTO_COMPLETE, trip.getAutoCompleteMetadata().isCommentHiddenFromAutoComplete()); values.put(TripsTable.COLUMN_COSTCENTER_HIDDEN_AUTO_COMPLETE, trip.getAutoCompleteMetadata().isCostCenterHiddenFromAutoComplete()); if (databaseOperationMetadata.getOperationFamilyType() == OperationFamilyType.Sync) { values.putAll(syncStateAdapter.write(trip.getSyncState())); } else { values.putAll(syncStateAdapter.writeUnsynced(trip.getSyncState())); } return values; } 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 writeUnsynced() throws Exception { final String sync = "sync"; final ContentValues syncValues = new ContentValues(); syncValues.put(sync, sync); when(mSyncStateAdapter.writeUnsynced(mSyncState)).thenReturn(syncValues); final ContentValues contentValues = mTripDatabaseAdapter.write(mTrip, new DatabaseOperationMetadata()); assertEquals(NAME, contentValues.getAsString("name")); assertEquals(START_DATE, (long) contentValues.getAsLong("from_date")); assertEquals(END_DATE, (long) contentValues.getAsLong("to_date")); assertEquals(START_TIMEZONE, contentValues.getAsString("from_timezone")); assertEquals(END_TIMEZONE, contentValues.getAsString("to_timezone")); assertEquals(COMMENT, contentValues.getAsString("trips_comment")); assertEquals(COST_CENTER, contentValues.getAsString("trips_cost_center")); assertEquals(CURRENCY_CODE, contentValues.getAsString("trips_default_currency")); assertEquals(TRIP_UUID.toString(), contentValues.getAsString("entity_uuid")); assertEquals(NAME_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("name_hidden_auto_complete")); assertEquals(COMMENT_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("comment_hidden_auto_complete")); assertEquals(COST_CENTER_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("costcenter_hidden_auto_complete")); assertEquals(sync, contentValues.getAsString(sync)); assertFalse(contentValues.containsKey("miles_new")); assertFalse(contentValues.containsKey("trips_filters")); assertFalse(contentValues.containsKey("trip_processing_status")); assertFalse(contentValues.containsKey("price")); }
@Test public void write() throws Exception { final String sync = "sync"; final ContentValues syncValues = new ContentValues(); syncValues.put(sync, sync); when(mSyncStateAdapter.write(mSyncState)).thenReturn(syncValues); final ContentValues contentValues = mTripDatabaseAdapter.write(mTrip, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(NAME, contentValues.getAsString("name")); assertEquals(START_DATE, (long) contentValues.getAsLong("from_date")); assertEquals(END_DATE, (long) contentValues.getAsLong("to_date")); assertEquals(START_TIMEZONE, contentValues.getAsString("from_timezone")); assertEquals(END_TIMEZONE, contentValues.getAsString("to_timezone")); assertEquals(COMMENT, contentValues.getAsString("trips_comment")); assertEquals(COST_CENTER, contentValues.getAsString("trips_cost_center")); assertEquals(CURRENCY_CODE, contentValues.getAsString("trips_default_currency")); assertEquals(TRIP_UUID.toString(), contentValues.getAsString("entity_uuid")); assertEquals(NAME_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("name_hidden_auto_complete")); assertEquals(COMMENT_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("comment_hidden_auto_complete")); assertEquals(COST_CENTER_HIDDEN_FROM_AUTO_COMPLETE, contentValues.getAsBoolean("costcenter_hidden_auto_complete")); assertEquals(sync, contentValues.getAsString(sync)); assertFalse(contentValues.containsKey("miles_new")); assertFalse(contentValues.containsKey("trips_filters")); assertFalse(contentValues.containsKey("trip_processing_status")); assertFalse(contentValues.containsKey("price")); }