PaymentMethodDatabaseAdapter implements DatabaseAdapter<PaymentMethod> { @NonNull @Override public ContentValues write(@NonNull PaymentMethod paymentMethod, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { final ContentValues values = new ContentValues(); values.put(PaymentMethodsTable.COLUMN_METHOD, paymentMethod.getMethod()); values.put(PaymentMethodsTable.COLUMN_CUSTOM_ORDER_ID, paymentMethod.getCustomOrderId()); values.put(PaymentMethodsTable.COLUMN_UUID, paymentMethod.getUuid().toString()); values.put(PaymentMethodsTable.COLUMN_REIMBURSABLE, paymentMethod.isReimbursable()); if (databaseOperationMetadata.getOperationFamilyType() == OperationFamilyType.Sync) { values.putAll(mSyncStateAdapter.write(paymentMethod.getSyncState())); } else { values.putAll(mSyncStateAdapter.writeUnsynced(paymentMethod.getSyncState())); } return values; } PaymentMethodDatabaseAdapter();  PaymentMethodDatabaseAdapter(@NonNull SyncStateAdapter syncStateAdapter); @NonNull @Override PaymentMethod read(@NonNull Cursor cursor); @NonNull @Override ContentValues write(@NonNull PaymentMethod paymentMethod, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @NonNull @Override PaymentMethod build(@NonNull PaymentMethod paymentMethod, 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 = mPaymentMethodDatabaseAdapter.write(mPaymentMethod, new DatabaseOperationMetadata()); assertEquals(METHOD, contentValues.getAsString("method")); assertEquals(sync, contentValues.getAsString(sync)); assertEquals(CUSTOM_ORDER, (int) contentValues.getAsInteger("custom_order_id")); assertEquals(PM_UUID.toString(), contentValues.getAsString("entity_uuid")); assertFalse(contentValues.containsKey("id")); }
@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 = mPaymentMethodDatabaseAdapter.write(mPaymentMethod, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(METHOD, contentValues.getAsString("method")); assertEquals(sync, contentValues.getAsString(sync)); assertEquals(CUSTOM_ORDER, (int) contentValues.getAsInteger("custom_order_id")); assertEquals(PM_UUID.toString(), contentValues.getAsString("entity_uuid")); assertFalse(contentValues.containsKey("id")); }