Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 298d675e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[KV] Add missing tests for handleCancel()"

parents a8aaa38d e2801ba2
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.when;
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 @@ public class KeyValueBackupTaskTest {
        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);