### Question:
ShortcutManagerCompat { public static boolean requestPinShortcut(@NonNull final Context context, @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).requestPinShortcut( shortcut.toShortcutInfo(), callback); } if (!isRequestPinShortcutSupported(context)) { return false; } Intent intent = shortcut.addToIntent(new Intent(ACTION_INSTALL_SHORTCUT)); if (callback == null) { context.sendBroadcast(intent); return true; } context.sendOrderedBroadcast(intent, null, new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { try { callback.sendIntent(context, 0, null, null, null); } catch (IntentSender.SendIntentException e) { } } }, null, Activity.RESULT_OK, null, null); return true; } private  ShortcutManagerCompat(); static boolean isRequestPinShortcutSupported(@NonNull Context context); static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback); @NonNull static Intent createShortcutResultIntent(@NonNull Context context,
            @NonNull ShortcutInfoCompat shortcut);  }### Answer:
@Test @SmallTest @SdkSuppress(minSdkVersion = 26) public void testRequestPinShortcut_v26() throws Throwable { ShortcutManager mockShortcutManager = mock(ShortcutManager.class); doReturn(mockShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE)); when(mockShortcutManager.requestPinShortcut( any(ShortcutInfo.class), nullable(IntentSender.class))).thenReturn(true); assertTrue(ShortcutManagerCompat.requestPinShortcut(mContext, mInfoCompat, null)); ArgumentCaptor<ShortcutInfo> captor = ArgumentCaptor.forClass(ShortcutInfo.class); verify(mockShortcutManager, times(1)).requestPinShortcut(captor.capture(), (IntentSender) isNull()); assertEquals("test-id", captor.getValue().getId()); }
@LargeTest @Test @SdkSuppress(maxSdkVersion = 25) public void testRequestPinShortcut_v4_noCallback() throws Throwable { setMockPm(mockResolveInfo(null)); BlockingBroadcastReceiver receiver = new BlockingBroadcastReceiver(ShortcutManagerCompat.ACTION_INSTALL_SHORTCUT); assertTrue(ShortcutManagerCompat.requestPinShortcut(mContext, mInfoCompat, null)); verifyLegacyIntent(receiver.blockingGetIntent()); }
@LargeTest @Test @SdkSuppress(maxSdkVersion = 25) public void testRequestPinShortcut_v4_withCallback() throws Throwable { setMockPm(mockResolveInfo(null)); BlockingBroadcastReceiver receiver = new BlockingBroadcastReceiver(ShortcutManagerCompat.ACTION_INSTALL_SHORTCUT); BlockingBroadcastReceiver callback = new BlockingBroadcastReceiver("shortcut-callback"); assertTrue(ShortcutManagerCompat.requestPinShortcut(mContext, mInfoCompat, PendingIntent.getBroadcast(mContext, 0, new Intent("shortcut-callback"), PendingIntent.FLAG_ONE_SHOT).getIntentSender())); verifyLegacyIntent(receiver.blockingGetIntent()); assertNotNull(callback.blockingGetIntent()); }