### Question:
PendingDynamicLinkData { @Nullable public Intent getUpdateAppIntent(@NonNull Context context) { int versionCode; if (getMinimumAppVersion() == 0) { return null; } try { versionCode = context .getPackageManager() .getPackageInfo(context.getApplicationContext().getPackageName(), 0) .versionCode; } catch (NameNotFoundException e) { return null; } if (versionCode < getMinimumAppVersion() && getRedirectUrl() != null) { return new Intent(Intent.ACTION_VIEW) .setData(getRedirectUrl()) .setPackage(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE); } return null; } @VisibleForTesting  PendingDynamicLinkData(DynamicLinkData dynamicLinkData); protected  PendingDynamicLinkData(
      @Nullable String deepLink, int minVersion, long clickTimestamp, @Nullable Uri redirectUrl); @Nullable Bundle getExtensions(); @Nullable Uri getLink(); int getMinimumAppVersion(); long getClickTimestamp(); @VisibleForTesting Uri getRedirectUrl(); @Nullable Intent getUpdateAppIntent(@NonNull Context context);  }### Answer:
@Test public void testGetUpdateAppIntent_UpdateRequired_CurrentVersionZero() { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(MINIMUM_VERSION)); packageInfo.versionCode = 0; Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNotNull(intent); assertEquals(intent.getData(), updateAppUri); }
@Test public void testGetUpdateAppIntent_UpdateRequired_MinVersionHigher() { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(MINIMUM_VERSION)); packageInfo.versionCode = MINIMUM_VERSION - 1; Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNotNull(intent); assertEquals(intent.getData(), updateAppUri); }
@Test public void testGetUpdateAppIntent_NoUpdate_ZeroMinVersion() { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(0)); packageInfo.versionCode = 0; Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNull(intent); }
@Test public void testGetUpdateAppIntent_NoUpdate_SameVersion() { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(MINIMUM_VERSION)); packageInfo.versionCode = MINIMUM_VERSION; Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNull(intent); }
@Test public void testGetUpdateAppIntent_NoUpdate_MinVersionLower() { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(MINIMUM_VERSION)); packageInfo.versionCode = MINIMUM_VERSION + 1; Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNull(intent); }
@Test public void testGetUpdateAppIntent_NameNotFoundException() throws Exception { PendingDynamicLinkData pendingDynamicLinkData = new PendingDynamicLinkData(createDynamicLinkDataWithMinVersion(MINIMUM_VERSION)); packageInfo.versionCode = 0; when(mockPackageManager.getPackageInfo(eq(PACKAGE_NAME), anyInt())) .thenThrow(new PackageManager.NameNotFoundException()); Intent intent = pendingDynamicLinkData.getUpdateAppIntent(mockContext); assertNull(intent); }