### Question:
NavDeepLink { @Nullable Bundle getMatchingArguments(@NonNull Uri deepLink) { Matcher matcher = mPattern.matcher(deepLink.toString()); if (!matcher.matches()) { return null; } Bundle bundle = new Bundle(); int size = mArguments.size(); for (int index = 0; index < size; index++) { String argument = mArguments.get(index); bundle.putString(argument, Uri.decode(matcher.group(index + 1))); } return bundle; } NavDeepLink(@NonNull String uri);   }### Answer:
@Test public void deepLinkArgumentMatch() { String deepLinkArgument = DEEP_LINK_EXACT_HTTPS + "/users/{id}/posts"; NavDeepLink deepLink = new NavDeepLink(deepLinkArgument); String id = "2"; Bundle matchArgs = deepLink.getMatchingArguments( Uri.parse(deepLinkArgument.replace("{id}", id))); assertThat(matchArgs, not(nullValue())); assertThat(matchArgs.getString("id"), is(id)); }
@Test public void deepLinkArgumentMatchEncoded() throws UnsupportedEncodingException { String deepLinkArgument = DEEP_LINK_EXACT_HTTPS + "/users/{name}/posts"; NavDeepLink deepLink = new NavDeepLink(deepLinkArgument); String name = "John Doe"; Bundle matchArgs = deepLink.getMatchingArguments( Uri.parse(deepLinkArgument.replace("{name}", Uri.encode(name)))); assertThat(matchArgs, not(nullValue())); assertThat(matchArgs.getString("name"), is(name)); }
@Test public void deepLinkMultipleArgumentMatch() { String deepLinkArgument = DEEP_LINK_EXACT_HTTPS + "/users/{id}/posts/{postId}"; NavDeepLink deepLink = new NavDeepLink(deepLinkArgument); String id = "2"; String postId = "42"; Bundle matchArgs = deepLink.getMatchingArguments( Uri.parse(deepLinkArgument.replace("{id}", id).replace("{postId}", postId))); assertThat(matchArgs, not(nullValue())); assertThat(matchArgs.getString("id"), is(id)); assertThat(matchArgs.getString("postId"), is(postId)); }
@Test public void deepLinkMultipleMatch() { String deepLinkMultiple = DEEP_LINK_EXACT_HTTPS + "/users/{id}/posts/.*"; NavDeepLink deepLink = new NavDeepLink(deepLinkMultiple); String id = "2"; Bundle matchArgs = deepLink.getMatchingArguments( Uri.parse(deepLinkMultiple.replace("{id}", id))); assertThat(matchArgs, not(nullValue())); assertThat(matchArgs.getString("id"), is(id)); }