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

Commit 4d006f59 authored by Nate Myren's avatar Nate Myren Committed by Patrick Baumann
Browse files

Added test coverage to Context.startActivityAsUser

Test: atest ContextTest
Fixes: 127711435
Change-Id: I7629da8d15ded1b2ac0907f2284289fdb07879ec
(cherry picked from commit 7c491a53)
parent 04cb6d1c
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.content;
import static org.junit.Assert.assertEquals;

import android.app.ActivityThread;
import android.os.UserHandle;
import android.view.WindowManager;

import androidx.test.InstrumentationRegistry;
@@ -58,4 +59,32 @@ public class ContextTest {
        assertEquals(defaultDisplayContext.getDisplay().getDisplayId(),
                defaultDisplayContext.getDisplayId());
    }

    @Test(expected = NullPointerException.class)
    public void testStartActivityAsUserNullIntentNullUser() {
        final Context testContext =
                InstrumentationRegistry.getInstrumentation().getTargetContext();
        testContext.startActivityAsUser(null, null);
    }

    @Test(expected = NullPointerException.class)
    public void testStartActivityAsUserNullIntentNonNullUser() {
        final Context testContext =
                InstrumentationRegistry.getInstrumentation().getTargetContext();
        testContext.startActivityAsUser(null, new UserHandle(UserHandle.USER_ALL));
    }

    @Test(expected = NullPointerException.class)
    public void testStartActivityAsUserNonNullIntentNullUser() {
        final Context testContext =
                InstrumentationRegistry.getInstrumentation().getTargetContext();
        testContext.startActivityAsUser(new Intent(), null);
    }

    @Test(expected = RuntimeException.class)
    public void testStartActivityAsUserNonNullIntentNonNullUser() {
        final Context testContext =
                InstrumentationRegistry.getInstrumentation().getTargetContext();
        testContext.startActivityAsUser(new Intent(), new UserHandle(UserHandle.USER_ALL));
    }
}