CategoryDatabaseAdapter implements DatabaseAdapter<Category> { @Override @NonNull public ContentValues write(@NonNull Category category, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { final ContentValues values = new ContentValues(); values.put(CategoriesTable.COLUMN_NAME, category.getName()); values.put(CategoriesTable.COLUMN_CODE, category.getCode()); values.put(CategoriesTable.COLUMN_CUSTOM_ORDER_ID, category.getCustomOrderId()); values.put(CategoriesTable.COLUMN_UUID, category.getUuid().toString()); if (databaseOperationMetadata.getOperationFamilyType() == OperationFamilyType.Sync) { values.putAll(mSyncStateAdapter.write(category.getSyncState())); } else { values.putAll(mSyncStateAdapter.writeUnsynced(category.getSyncState())); } return values; } CategoryDatabaseAdapter();  CategoryDatabaseAdapter(@NonNull SyncStateAdapter syncStateAdapter); @Override @NonNull Category read(@NonNull Cursor cursor); @Override @NonNull ContentValues write(@NonNull Category category, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @Override @NonNull Category build(@NonNull Category category, 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 = mCategoryDatabaseAdapter.write(mCategory, new DatabaseOperationMetadata()); assertEquals(NAME, contentValues.getAsString(NAME_KEY)); assertEquals(CODE, contentValues.getAsString(CODE_KEY)); assertEquals(sync, contentValues.getAsString(sync)); assertEquals(CUSTOM_ORDER_ID, (int) contentValues.getAsInteger(CUSTOM_ORDER_ID_KEY)); assertEquals(CAT_UUID.toString(), contentValues.getAsString(UUID_KEY)); }
@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 = mCategoryDatabaseAdapter.write(mCategory, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(NAME, contentValues.getAsString(NAME_KEY)); assertEquals(CODE, contentValues.getAsString(CODE_KEY)); assertEquals(sync, contentValues.getAsString(sync)); assertEquals(CUSTOM_ORDER_ID, (int) contentValues.getAsInteger(CUSTOM_ORDER_ID_KEY)); assertEquals(CAT_UUID.toString(), contentValues.getAsString(UUID_KEY)); }