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

Commit 1c14929a authored by Makoto Onuki's avatar Makoto Onuki Committed by android-build-merger
Browse files

Merge \"Fix some exception messages and enhance unit tets\" into nyc-mr1-dev

am: 5b8f5fd3

Change-Id: If0c711f8f9cef00b4a8fb279b5c5996f2995d1f0
parents 53d354c4 5b8f5fd3
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -254,9 +254,9 @@ public final class ShortcutInfo implements Parcelable {
     */
    public void enforceMandatoryFields() {
        Preconditions.checkStringNotEmpty(mId, "Shortcut ID must be provided");
        Preconditions.checkNotNull(mActivity, "activity must be provided");
        Preconditions.checkNotNull(mActivity, "Activity must be provided");
        if (mTitle == null && mTitleResId == 0) {
            throw new IllegalArgumentException("Shortcut title must be provided");
            throw new IllegalArgumentException("Short label must be provided");
        }
        Preconditions.checkNotNull(mIntent, "Shortcut Intent must be provided");
    }
+1 −1
Original line number Diff line number Diff line
@@ -908,7 +908,7 @@ class ShortcutPackage extends ShortcutPackageItem {
                if (operation != ShortcutService.OPERATION_UPDATE) {
                    // This method may be called before validating shortcuts, so this may happen,
                    // and is a caller side error.
                    throw new NullPointerException("activity must be provided");
                    throw new NullPointerException("Activity must be provided");
                }
                continue; // Activity can be null for update.
            }
+4 −0
Original line number Diff line number Diff line
@@ -697,6 +697,10 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
        return getInstrumentation().getContext();
    }

    protected ShortcutManager getManager() {
        return mManager;
    }

    protected void deleteAllSavedFiles() {
        // Empty the data directory.
        if (mInjectedFilePathRoot.exists()) {
+64 −21
Original line number Diff line number Diff line
@@ -56,35 +56,78 @@ public class ShortcutManagerTest2 extends BaseShortcutManagerTest {
    // ShortcutInfo tests

    public void testShortcutInfoMissingMandatoryFields() {
        // Disable throttling.
        mService.updateConfigurationLocked(
                ShortcutService.ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=99999999,"
                + ShortcutService.ConfigConstants.KEY_MAX_SHORTCUTS + "=99999999"
        );

        assertExpectException(
                IllegalArgumentException.class,
                "ID must be provided",
                () -> new ShortcutInfo.Builder(getTestContext()).build());
        assertExpectException(
                NullPointerException.class,
                "Intent action must be set",

        assertExpectException(NullPointerException.class, "Intent action must be set",
                () -> new ShortcutInfo.Builder(getTestContext()).setIntent(new Intent()));

        assertExpectException(NullPointerException.class, "Activity must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext()).setId("id").build();
            assertTrue(getManager().setDynamicShortcuts(list(si)));
        });

        assertExpectException(
                NullPointerException.class,
                "activity must be provided",
                () -> new ShortcutInfo.Builder(getTestContext()).setId("id").build()
                        .enforceMandatoryFields());
                IllegalArgumentException.class, "Short label must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName(getTestContext().getPackageName(), "s"))
                    .build();
            assertTrue(getManager().setDynamicShortcuts(list(si)));
        });

        assertExpectException(
                IllegalArgumentException.class,
                "title must be provided",
                () -> new ShortcutInfo.Builder(getTestContext()).setId("id")
                        .setActivity(
                                new ComponentName(getTestContext().getPackageName(), "s"))
                        .build()
                        .enforceMandatoryFields());
                IllegalArgumentException.class, "Short label must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName(getTestContext().getPackageName(), "s"))
                    .build();
            assertTrue(getManager().addDynamicShortcuts(list(si)));
        });

        assertExpectException(NullPointerException.class, "Intent must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName(getTestContext().getPackageName(), "s"))
                    .setShortLabel("x")
                    .build();
            assertTrue(getManager().setDynamicShortcuts(list(si)));
        });

        assertExpectException(NullPointerException.class, "Intent must be provided", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName(getTestContext().getPackageName(), "s"))
                    .setShortLabel("x")
                    .build();
            assertTrue(getManager().addDynamicShortcuts(list(si)));
        });

        assertExpectException(
                NullPointerException.class,
                "Intent must be provided",
                () -> new ShortcutInfo.Builder(getTestContext()).setId("id")
                        .setActivity(
                                new ComponentName(getTestContext().getPackageName(), "s"))
                        .setTitle("x").build()
                        .enforceMandatoryFields());
                IllegalStateException.class, "package name mismatch", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName("xxx", "s"))
                    .build();
            assertTrue(getManager().setDynamicShortcuts(list(si)));
        });

        assertExpectException(
                IllegalStateException.class, "package name mismatch", () -> {
            ShortcutInfo si = new ShortcutInfo.Builder(getTestContext())
                    .setId("id")
                    .setActivity(new ComponentName("xxx", "s"))
                    .build();
            assertTrue(getManager().addDynamicShortcuts(list(si)));
        });
    }

    public void testShortcutInfoParcel() {
+3 −2
Original line number Diff line number Diff line
@@ -289,8 +289,6 @@ public class ShortcutManagerTestUtils {
            String expectedExceptionMessageRegex, Runnable r) {
        try {
            r.run();
            Assert.fail("Expected exception type " + expectedExceptionType.getName()
                    + " was not thrown (message=" + message + ")");
        } catch (Throwable e) {
            Assert.assertTrue(
                    "Expected exception type was " + expectedExceptionType.getName()
@@ -299,7 +297,10 @@ public class ShortcutManagerTestUtils {
            if (expectedExceptionMessageRegex != null) {
                MoreAsserts.assertContainsRegex(expectedExceptionMessageRegex, e.getMessage());
            }
            return; // Pass
        }
        Assert.fail("Expected exception type " + expectedExceptionType.getName()
                + " was not thrown");
    }

    public static List<ShortcutInfo> assertShortcutIds(List<ShortcutInfo> actualShortcuts,