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

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

Merge "Fix broken unit tests due to mockito upgrade." into oc-dev

parents 0ecd08bd d0010c5e
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.pm;

import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyStringOrNull;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.cloneShortcutList;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.hashSet;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list;
@@ -884,7 +886,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                    entryName = ShortcutInfo.getResourceEntryName(entryName);
                }
                return Integer.parseInt(entryName.substring(1)) + ressIdOffset;
            }).when(res).getIdentifier(anyString(), anyString(), anyString());
            }).when(res).getIdentifier(anyStringOrNull(), anyStringOrNull(), anyStringOrNull());
            return res;
        }).when(mMockPackageManager).getResourcesForApplicationAsUser(anyString(), anyInt());
    }
@@ -1612,7 +1614,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                eq(packageName),
                eq(userId),
                intentsCaptor.capture(),
                any(Bundle.class));
                anyOrNull(Bundle.class));
        return intentsCaptor.getValue();
    }

@@ -1671,7 +1673,7 @@ public abstract class BaseShortcutManagerTest extends InstrumentationTestCase {
                anyString(),
                anyInt(),
                any(Intent[].class),
                any(Bundle.class));
                anyOrNull(Bundle.class));
    }

    protected void assertStartShortcutThrowsException(@NonNull String packageName,
+6 −2
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package com.android.server.pm;

import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyStringOrNull;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllChooser;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDisabled;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamic;
@@ -2832,7 +2834,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
            // Not launchable.
            doReturn(ActivityManager.START_CLASS_NOT_FOUND)
                    .when(mMockActivityManagerInternal).startActivitiesAsPackage(
                            anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
                            anyStringOrNull(), anyInt(),
                            anyOrNull(Intent[].class), anyOrNull(Bundle.class));
            assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0,
                    ActivityNotFoundException.class);

@@ -2840,7 +2843,8 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
            doReturn(ActivityManager.START_CLASS_NOT_FOUND)
                    .when(mMockActivityManagerInternal)
                    .startActivitiesAsPackage(
                            anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
                            anyStringOrNull(), anyInt(),
                            anyOrNull(Intent[].class), anyOrNull(Bundle.class));
            assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0,
                    ActivityNotFoundException.class);
        });
+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.server.pm;

import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.anyOrNull;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertExpectException;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertForLauncherCallbackNoThrow;
import static com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith;
@@ -775,7 +776,7 @@ public class ShortcutManagerTest8 extends BaseShortcutManagerTest {
                    /* resultIntent=*/ null));

            // The intent should be sent right away.
            verify(mServiceContext, times(1)).sendIntentSender(any(IntentSender.class));
            verify(mServiceContext, times(1)).sendIntentSender(anyOrNull(IntentSender.class));
        });
    }

+10 −0
Original line number Diff line number Diff line
@@ -58,6 +58,8 @@ import org.hamcrest.Matcher;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.mockito.hamcrest.MockitoHamcrest;

@@ -733,6 +735,14 @@ public class ShortcutManagerTestUtils {
        fail("Timed out for: " + message);
    }

    public static final <T> T anyOrNull(Class<T> clazz) {
        return ArgumentMatchers.argThat(value -> true);
    }

    public static final String anyStringOrNull() {
        return ArgumentMatchers.argThat(value -> true);
    }

    public static ShortcutListAsserter assertWith(List<ShortcutInfo> list) {
        return new ShortcutListAsserter(list);
    }