BaseDeepLinkDelegate { public DeepLinkResult dispatchFrom(Activity activity) { validateInput(activity); return dispatchFrom(activity, activity.getIntent()); } BaseDeepLinkDelegate(List<? extends BaseRegistry> registries);  BaseDeepLinkDelegate(List<? extends BaseRegistry> registries, ErrorHandler errorHandler);  BaseDeepLinkDelegate(
    List<? extends BaseRegistry> registries,
    Map<String, String> configurablePathSegmentReplacements
  );  BaseDeepLinkDelegate(
    List<? extends BaseRegistry> registries,
    Map<String, String> configurablePathSegmentReplacements,
    ErrorHandler errorHandler
  ); List<? extends BaseRegistry> getRegistries(); DeepLinkResult dispatchFrom(Activity activity); DeepLinkResult dispatchFrom(Activity activity, Intent sourceIntent); @NonNull DeepLinkResult createResult(
    Activity activity, Intent sourceIntent, DeepLinkEntry deepLinkEntry
  ); boolean supportsUri(String uriString);  }
@Test public void testErrorHanderWithDuplicateMartch() { String deeplinkUrl = "airbnb: String matchUrl = "airbnb: DeepLinkEntry entry = deepLinkEntry(deeplinkUrl); Uri uri = mock(Uri.class); when(uri.toString()) .thenReturn(matchUrl); Intent intent = mock(Intent.class); when(intent.getData()) .thenReturn(uri); Context appContext = mock(Context.class); Activity activity = mock(Activity.class); when(activity.getIntent()) .thenReturn(intent); when(activity.getApplicationContext()) .thenReturn(appContext); TestErrorHandler errorHandler = new TestErrorHandler(); TestDeepLinkDelegate testDelegate = getTwoRegistriesTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry}), Arrays.asList(new DeepLinkEntry[]{entry}), errorHandler); DeepLinkResult result = testDelegate.dispatchFrom(activity, intent); assertThat(errorHandler.duplicatedMatchCalled()).isTrue(); assertThat(errorHandler.getDuplicatedMatches()).isNotNull(); assertThat(errorHandler.getDuplicatedMatches().size()).isEqualTo(2); assertThat(errorHandler.getDuplicatedMatches().get(0)).isEqualTo(entry); assertThat(errorHandler.getDuplicatedMatches().get(1)).isEqualTo(entry); assertThat(errorHandler.getUriString()).isEqualTo(matchUrl); assertThat(result.getDeepLinkEntry().equals(entry)); }
@Test public void testErrorHandlerNotGettingCalled() { String deeplinkUrl1 = "airbnb: String deeplinkUrl2 = "airbnb: String matchUrl = "airbnb: DeepLinkEntry entry1 = deepLinkEntry(deeplinkUrl1); DeepLinkEntry entry2 = deepLinkEntry(deeplinkUrl2); Uri uri = mock(Uri.class); when(uri.toString()) .thenReturn(matchUrl); Intent intent = mock(Intent.class); when(intent.getData()) .thenReturn(uri); Context appContext = mock(Context.class); Activity activity = mock(Activity.class); when(activity.getIntent()) .thenReturn(intent); when(activity.getApplicationContext()) .thenReturn(appContext); TestErrorHandler errorHandler = new TestErrorHandler(); TestDeepLinkDelegate testDelegate = getTwoRegistriesTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry1}), Arrays.asList(new DeepLinkEntry[]{entry2}), errorHandler); DeepLinkResult result = testDelegate.dispatchFrom(activity, intent); assertThat(errorHandler.duplicatedMatchCalled()).isFalse(); assertThat(result.getDeepLinkEntry().equals(entry2)); }
@Test public void testDispatchNullActivity() { DeepLinkEntry entry = deepLinkEntry("airbnb: TestDeepLinkDelegate testDelegate = getOneRegistryTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry}), null); String message = null; try { testDelegate.dispatchFrom(null); } catch (NullPointerException e) { message = e.getMessage(); } assertThat(message).isEqualTo("activity == null"); }
@Test public void testDispatchNullActivityNullIntent() { DeepLinkEntry entry = deepLinkEntry("airbnb: TestDeepLinkDelegate testDelegate = getOneRegistryTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry}), null); String message = null; try { testDelegate.dispatchFrom(null, null); } catch (NullPointerException e) { message = e.getMessage(); } assertThat(message).isEqualTo("activity == null"); }
@Test public void testDispatchNullIntent() { DeepLinkEntry entry = deepLinkEntry("airbnb: TestDeepLinkDelegate testDelegate = getOneRegistryTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry}), null); Activity activity = mock(Activity.class); when(activity.getIntent()) .thenReturn(null); String message = null; try { testDelegate.dispatchFrom(activity); } catch (NullPointerException e) { message = e.getMessage(); } assertThat(message).isEqualTo("sourceIntent == null"); }
@Test public void testDispatchNonNullActivityNullIntent() { DeepLinkEntry entry = deepLinkEntry("airbnb: TestDeepLinkDelegate testDelegate = getOneRegistryTestDelegate(Arrays.asList(new DeepLinkEntry[]{entry}), null); Activity activity = mock(Activity.class); when(activity.getIntent()) .thenReturn(null); String message = null; try { testDelegate.dispatchFrom(activity, null); } catch (NullPointerException e) { message = e.getMessage(); } assertThat(message).isEqualTo("sourceIntent == null"); }