ReceiptBackupListener extends DatabaseBackupListener<Receipt> { @Override public void onUpdateSuccess(@NonNull Receipt oldReceipt, @NonNull Receipt newReceipt, @NonNull DatabaseOperationMetadata databaseOperationMetadata) { if (newReceipt.getFile() != null) { mDriveDatabaseManager.syncDatabase(); } if (databaseOperationMetadata.getOperationFamilyType() != OperationFamilyType.Sync) { mDriveReceiptsManager.handleInsertOrUpdate(newReceipt); } } ReceiptBackupListener(@NonNull DriveDatabaseManager driveDatabaseManager, @NonNull DriveReceiptsManager driveReceiptsManager); @Override void onInsertSuccess(@NonNull Receipt receipt, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @Override void onUpdateSuccess(@NonNull Receipt oldReceipt, @NonNull Receipt newReceipt, @NonNull DatabaseOperationMetadata databaseOperationMetadata); @Override void onDeleteSuccess(@NonNull Receipt receipt, @NonNull DatabaseOperationMetadata databaseOperationMetadata);  }
@Test public void onUpdateSuccess() { mListener.onUpdateSuccess(mOldReceipt, mReceipt, new DatabaseOperationMetadata()); verify(mDriveDatabaseManager, never()).syncDatabase(); verify(mDriveReceiptsManager).handleInsertOrUpdate(mReceipt); }
@Test public void onSyncUpdateSuccess() { mListener.onUpdateSuccess(mOldReceipt, mReceipt, new DatabaseOperationMetadata(OperationFamilyType.Sync)); verify(mDriveDatabaseManager, never()).syncDatabase(); verify(mDriveReceiptsManager, never()).handleInsertOrUpdate(any(Receipt.class)); }
@Test public void onSyncUpdateSuccessForReceiptWithFile() { when(mReceipt.getFile()).thenReturn(mock(File.class)); mListener.onUpdateSuccess(mOldReceipt, mReceipt, new DatabaseOperationMetadata(OperationFamilyType.Sync)); verify(mDriveDatabaseManager).syncDatabase(); verify(mDriveReceiptsManager, never()).handleInsertOrUpdate(any(Receipt.class)); }