SyncStateAdapter { @NonNull public SyncState get(@NonNull SyncState syncState, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { if (databaseOperationMetadata.getOperationFamilyType() == OperationFamilyType.Sync) { return syncState; } else { final Identifier driveIdentifier = syncState.getSyncId(SyncProvider.GoogleDrive); final IdentifierMap identifierMap; if (driveIdentifier != null) { identifierMap = new IdentifierMap(Collections.singletonMap(SyncProvider.GoogleDrive, driveIdentifier)); } else { identifierMap = null; } final SyncStatusMap syncStatusMap = new SyncStatusMap(Collections.singletonMap(SyncProvider.GoogleDrive, false)); final MarkedForDeletionMap markedForDeletionMap = new MarkedForDeletionMap(Collections.singletonMap(SyncProvider.GoogleDrive, syncState.isMarkedForDeletion(SyncProvider.GoogleDrive))); return new DefaultSyncState(identifierMap, syncStatusMap, markedForDeletionMap, syncState.getLastLocalModificationTime()); } } @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 getWhenSyncing() throws Exception { assertEquals(mSyncState, mSyncStateAdapter.get(mSyncState, new DatabaseOperationMetadata(OperationFamilyType.Sync))); }
@Test public void getWhenNotSyncing() throws Exception { final SyncState nonSyncGet = mSyncStateAdapter.get(mSyncState, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(nonSyncGet.getSyncId(SyncProvider.GoogleDrive), mSyncState.getSyncId(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.isSynced(SyncProvider.GoogleDrive), mSyncState.isSynced(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.isMarkedForDeletion(SyncProvider.GoogleDrive), mSyncState.isMarkedForDeletion(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.getLastLocalModificationTime(), mSyncState.getLastLocalModificationTime()); }
@Test public void getWhenNotSyncingWithNullId() throws Exception { when(mSyncState.getSyncId(SyncProvider.GoogleDrive)).thenReturn(null); final SyncState nonSyncGet = mSyncStateAdapter.get(mSyncState, new DatabaseOperationMetadata(OperationFamilyType.Sync)); assertEquals(nonSyncGet.getSyncId(SyncProvider.GoogleDrive), mSyncState.getSyncId(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.isSynced(SyncProvider.GoogleDrive), mSyncState.isSynced(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.isMarkedForDeletion(SyncProvider.GoogleDrive), mSyncState.isMarkedForDeletion(SyncProvider.GoogleDrive)); assertEquals(nonSyncGet.getLastLocalModificationTime(), mSyncState.getLastLocalModificationTime()); }