ColumnDatabaseAdapter implements DatabaseAdapter<Column<Receipt>> { @NonNull @Override public ContentValues write(@NonNull Column<Receipt> column, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { final ContentValues values = new ContentValues(); values.put(AbstractColumnTable.COLUMN_TYPE, column.getType()); values.put(AbstractColumnTable.COLUMN_CUSTOM_ORDER_ID, column.getCustomOrderId()); values.put(AbstractColumnTable.COLUMN_UUID, column.getUuid().toString()); if (databaseOperationMetadata.getOperationFamilyType() == OperationFamilyType.Sync) { values.putAll(mSyncStateAdapter.write(column.getSyncState())); } else { values.putAll(mSyncStateAdapter.writeUnsynced(column.getSyncState())); } return values; } ColumnDatabaseAdapter(@NonNull ColumnDefinitions<Receipt> receiptColumnDefinitions);  ColumnDatabaseAdapter(@NonNull ColumnDefinitions<Receipt> receiptColumnDefinitions, @NonNull SyncStateAdapter syncStateAdapter); @NonNull @Override Column<Receipt> read(@NonNull Cursor cursor); @NonNull @Override ContentValues write(@NonNull Column<Receipt> column, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @NonNull @Override Column<Receipt> build(@NonNull Column<Receipt> column, int primaryKey, @NonNull UUID uuid, @NonNull DatabaseOperationMetadata databaseOperationMetadata);  }
@Test public void write() throws Exception { final String sync = "sync"; final ContentValues syncValues = new ContentValues(); syncValues.put(sync, sync); when(syncStateAdapter.writeUnsynced(syncState)).thenReturn(syncValues); final ContentValues contentValues = columnDatabaseAdapter.write(column, new DatabaseOperationMetadata()); assertEquals(Integer.valueOf(TYPE), contentValues.getAsInteger(AbstractColumnTable.COLUMN_TYPE)); assertEquals(sync, contentValues.getAsString(sync)); assertFalse(contentValues.containsKey(AbstractColumnTable.COLUMN_ID)); assertEquals(CUSTOM_ORDER_ID, (long) contentValues.getAsLong(AbstractSqlTable.COLUMN_CUSTOM_ORDER_ID)); assertEquals(COLUMN_UUID.toString(), contentValues.getAsString(AbstractSqlTable.COLUMN_UUID)); }
@Test public void writeUnsynced() throws Exception { final String sync = "sync"; final ContentValues syncValues = new ContentValues(); syncValues.put(sync, sync); when(syncStateAdapter.write(syncState)).thenReturn(syncValues); final ContentValues contentValues = columnDatabaseAdapter.write(column, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(Integer.valueOf(TYPE), contentValues.getAsInteger(AbstractColumnTable.COLUMN_TYPE)); assertEquals(sync, contentValues.getAsString(sync)); assertFalse(contentValues.containsKey(AbstractColumnTable.COLUMN_ID)); assertEquals(CUSTOM_ORDER_ID, (long) contentValues.getAsLong(AbstractSqlTable.COLUMN_CUSTOM_ORDER_ID)); assertEquals(COLUMN_UUID.toString(), contentValues.getAsString(AbstractSqlTable.COLUMN_UUID)); }