DriveReceiptsManager { public synchronized void handleDelete(@NonNull final Receipt receipt) { if (!mIsInitializing.get()) { handleDeleteInternal(receipt); } } DriveReceiptsManager(@NonNull TableController<Receipt> receiptsTableController, @NonNull TripsTable tripsTable,
                                @NonNull ReceiptsTable receiptsTable, @NonNull DriveStreamsManager driveTaskManager,
                                @NonNull DriveDatabaseManager driveDatabaseManager, @NonNull NetworkManager networkManager,
                                @NonNull Analytics analytics);  DriveReceiptsManager(@NonNull TableController<Receipt> receiptsTableController,
                                @NonNull TripsTable tripsTable,
                                @NonNull ReceiptsTable receiptsTable,
                                @NonNull DriveStreamsManager driveTaskManager,
                                @NonNull DriveDatabaseManager driveDatabaseManager,
                                @NonNull NetworkManager networkManager,
                                @NonNull Analytics analytics,
                                @NonNull DriveStreamMappings driveStreamMappings,
                                @NonNull ReceiptBuilderFactoryFactory receiptBuilderFactoryFactory,
                                @NonNull Scheduler observeOnScheduler,
                                @NonNull Scheduler subscribeOnScheduler); @SuppressLint("CheckResult") synchronized void syncReceipts(); synchronized void enable(); synchronized void disable(); synchronized void handleInsertOrUpdate(@NonNull final Receipt receipt); synchronized void handleDelete(@NonNull final Receipt receipt);  }
@Test public void handleDelete() { when(driveStreamsManager.deleteDriveFile(syncState1, true)).thenReturn(Single.just(newSyncState1)); when(syncState1.isSynced(SyncProvider.GoogleDrive)).thenReturn(false); when(syncState1.isMarkedForDeletion(SyncProvider.GoogleDrive)).thenReturn(true); driveReceiptsManager.handleDelete(receipt1); verify(receiptTableController).delete(receiptCaptor.capture(), operationMetadataCaptor.capture()); assertEquals(receipt1, receiptCaptor.getValue()); assertEquals(newSyncState1, receiptCaptor.getValue().getSyncState()); assertEquals(OperationFamilyType.Sync, operationMetadataCaptor.getValue().getOperationFamilyType()); }
@Test public void handleDeleteForStaleReceipt() { when(driveStreamsManager.deleteDriveFile(syncState1, true)).thenReturn(Single.just(newSyncState1)); when(syncState1.isSynced(SyncProvider.GoogleDrive)).thenReturn(false); when(syncState1.isMarkedForDeletion(SyncProvider.GoogleDrive)).thenReturn(true); when(receiptsTable.findByPrimaryKey(RECEIPT_1_PRIMARY_KEY)).thenReturn(Single.just(mock(Receipt.class))); driveReceiptsManager.handleDelete(receipt1); verify(receiptTableController, never()).delete(receiptCaptor.capture(), operationMetadataCaptor.capture()); }
@Test public void handleDeleteWithoutNetwork() { when(driveStreamsManager.deleteDriveFile(syncState1, true)).thenReturn(Single.just(newSyncState1)); when(syncState1.isSynced(SyncProvider.GoogleDrive)).thenReturn(false); when(syncState1.isMarkedForDeletion(SyncProvider.GoogleDrive)).thenReturn(true); when(networkManager.isNetworkAvailable()).thenReturn(false); driveReceiptsManager.handleDelete(receipt1); verify(receiptTableController, never()).delete(receiptCaptor.capture(), operationMetadataCaptor.capture()); }
@Test(expected = IllegalArgumentException.class) public void handleDeleteForIllegalSyncState() { when(syncState1.isSynced(SyncProvider.GoogleDrive)).thenReturn(true); driveReceiptsManager.handleDelete(receipt1); }
@Test(expected = IllegalArgumentException.class) public void handleDeleteForIllegalMarkedForDeletionState() { when(syncState1.isMarkedForDeletion(SyncProvider.GoogleDrive)).thenReturn(false); driveReceiptsManager.handleDelete(receipt1); }