Merge "[KV] Add missing tests for handleCancel()"
diff --git a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
index 9fae43a..82d7ab8 100644
--- a/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
+++ b/services/robotests/src/com/android/server/backup/keyvalue/KeyValueBackupTaskTest.java
@@ -63,6 +63,7 @@
import static org.robolectric.Shadows.shadowOf;
import static org.robolectric.shadow.api.Shadow.extract;
import static org.testng.Assert.fail;
+import static org.testng.Assert.expectThrows;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.Collections.emptyList;
@@ -1941,6 +1942,29 @@
task.markCancel();
}
+ @Test
+ public void testHandleCancel_callsMarkCancelAndWaitCancel() throws Exception {
+ TransportMock transportMock = setUpInitializedTransport(mTransport);
+ setUpAgentWithData(PACKAGE_1);
+ KeyValueBackupTask task = spy(createKeyValueBackupTask(transportMock, PACKAGE_1));
+ doNothing().when(task).waitCancel();
+
+ task.handleCancel(true);
+
+ InOrder inOrder = inOrder(task);
+ inOrder.verify(task).markCancel();
+ inOrder.verify(task).waitCancel();
+ }
+
+ @Test
+ public void testHandleCancel_whenCancelAllFalse_throws() throws Exception {
+ TransportMock transportMock = setUpInitializedTransport(mTransport);
+ setUpAgentWithData(PACKAGE_1);
+ KeyValueBackupTask task = createKeyValueBackupTask(transportMock, PACKAGE_1);
+
+ expectThrows(IllegalArgumentException.class, () -> task.handleCancel(false));
+ }
+
private void runTask(KeyValueBackupTask task) {
// Pretend we are not on the main-thread to prevent RemoteCall from complaining
mShadowMainLooper.setCurrentThread(false);