### Question:
KeyValueBackupTask implements BackupRestoreTask, Runnable { @VisibleForTesting public void markCancel() { mReporter.onCancel(); mCancelled = true; RemoteCall pendingCall = mPendingCall; if (pendingCall != null) { pendingCall.cancel(); } } @VisibleForTesting  KeyValueBackupTask(
            UserBackupManagerService backupManagerService,
            TransportClient transportClient,
            String transportDirName,
            List<String> queue,
            @Nullable DataChangedJournal journal,
            KeyValueBackupReporter reporter,
            OnTaskFinishedListener taskFinishedListener,
            List<String> pendingFullBackups,
            boolean userInitiated,
            boolean nonIncremental); static KeyValueBackupTask start(
            UserBackupManagerService backupManagerService,
            TransportClient transportClient,
            String transportDirName,
            List<String> queue,
            @Nullable DataChangedJournal dataChangedJournal,
            IBackupObserver observer,
            @Nullable IBackupManagerMonitor monitor,
            OnTaskFinishedListener listener,
            List<String> pendingFullBackups,
            boolean userInitiated,
            boolean nonIncremental); @Override void run(); @Override void execute(); @Override void operationComplete(long unusedResult); @Override void handleCancel(boolean cancelAll); @VisibleForTesting void markCancel(); @VisibleForTesting void waitCancel(); @VisibleForTesting static final String STAGING_FILE_SUFFIX; @VisibleForTesting static final String NEW_STATE_FILE_SUFFIX; }### Answer:
@Test public void testRunTask_afterMarkCancel_doesNotCallAgentOrTransport() throws Exception { TransportMock transportMock = setUpInitializedTransport(mTransport); AgentMock agentMock = setUpAgentWithData(PACKAGE_1); KeyValueBackupTask task = createKeyValueBackupTask(transportMock, PACKAGE_1); task.markCancel(); runTask(task); verify(agentMock.agent, never()).onBackup(any(), any(), any()); verify(transportMock.transport, never()).performBackup(any(), any(), anyInt()); verify(transportMock.transport, never()).finishBackup(); }
@Test public void testMarkCancel_afterTaskFinished_returns() throws Exception { TransportMock transportMock = setUpInitializedTransport(mTransport); setUpAgentWithData(PACKAGE_1); KeyValueBackupTask task = createKeyValueBackupTask(transportMock, PACKAGE_1); runTask(task); task.markCancel(); }