SyncStateAdapter { @NonNull public SyncState read(@NonNull Cursor cursor) { final int driveIdentifierIndex = cursor.getColumnIndex(AbstractSqlTable.COLUMN_DRIVE_SYNC_ID); final int driveIsSyncedIndex = cursor.getColumnIndex(AbstractSqlTable.COLUMN_DRIVE_IS_SYNCED); final int driveMarkedForDeletionIndex = cursor.getColumnIndex(AbstractSqlTable.COLUMN_DRIVE_MARKED_FOR_DELETION); final int lastLocalModificationTimeIndex = cursor.getColumnIndex(AbstractSqlTable.COLUMN_LAST_LOCAL_MODIFICATION_TIME); final String driveIdentifierString = cursor.getString(driveIdentifierIndex); final boolean driveIsSynced = cursor.getInt(driveIsSyncedIndex) > 0; final boolean driveMarkedForDeletion = cursor.getInt(driveMarkedForDeletionIndex) > 0; final long lastLocalModificationTimeLong = cursor.getLong(lastLocalModificationTimeIndex); final Date lastLocalModificationTime = new Date(lastLocalModificationTimeLong); final IdentifierMap identifierMap; if (driveIdentifierString != null) { final Identifier driveIdentifier = new Identifier(driveIdentifierString); identifierMap = new IdentifierMap(Collections.singletonMap(SyncProvider.GoogleDrive, driveIdentifier)); } else { identifierMap = null; } final SyncStatusMap syncStatusMap = new SyncStatusMap(Collections.singletonMap(SyncProvider.GoogleDrive, driveIsSynced)); final MarkedForDeletionMap markedForDeletionMap = new MarkedForDeletionMap(Collections.singletonMap(SyncProvider.GoogleDrive, driveMarkedForDeletion)); return new DefaultSyncState(identifierMap, syncStatusMap, markedForDeletionMap, lastLocalModificationTime); } @Inject  SyncStateAdapter(); @NonNull SyncState read(@NonNull Cursor cursor); @NonNull ContentValues writeUnsynced(@NonNull SyncState syncState); @NonNull ContentValues write(@NonNull SyncState syncState); @NonNull ContentValues write(@NonNull SyncState syncState, boolean isUnsynced); @NonNull ContentValues deleteSyncData(@NonNull SyncProvider syncProvider); @NonNull SyncState get(@NonNull SyncState syncState, @NonNull DatabaseOperationMetadata databaseOperationMetadata);  }
@Test public void read() throws Exception { final DefaultSyncState syncState = new DefaultSyncState(mIdentifierMap, mSyncStatusMap, mMarkedForDeletionMap, mLastLocalModificationTime); assertEquals(syncState, mSyncStateAdapter.read(mCursor)); }
@Test public void readWithNullId() throws Exception { when(mCursor.getString(identifierIndex)).thenReturn(null); final DefaultSyncState syncState = new DefaultSyncState(null, mSyncStatusMap, mMarkedForDeletionMap, mLastLocalModificationTime); assertEquals(syncState, mSyncStateAdapter.read(mCursor)); }