|
| 1 | +// Copyright 2018 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.firebase.testing.dynamiclinks; |
| 16 | + |
| 17 | +import static com.google.common.truth.Truth.assertThat; |
| 18 | + |
| 19 | +import android.app.Activity; |
| 20 | +import android.net.Uri; |
| 21 | +import androidx.test.rule.ActivityTestRule; |
| 22 | +import androidx.test.runner.AndroidJUnit4; |
| 23 | +import com.google.android.gms.tasks.Task; |
| 24 | +import com.google.firebase.dynamiclinks.DynamicLink; |
| 25 | +import com.google.firebase.dynamiclinks.FirebaseDynamicLinks; |
| 26 | +import com.google.firebase.testing.common.Tasks2; |
| 27 | +import org.junit.Rule; |
| 28 | +import org.junit.Test; |
| 29 | +import org.junit.runner.RunWith; |
| 30 | + |
| 31 | +@RunWith(AndroidJUnit4.class) |
| 32 | +public final class DynamicLinksTest { |
| 33 | + |
| 34 | + @Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class); |
| 35 | + |
| 36 | + @Test |
| 37 | + public void buildDynamicLink_UriContainsCorrectComponents() throws Exception { |
| 38 | + FirebaseDynamicLinks dl = FirebaseDynamicLinks.getInstance(); |
| 39 | + Uri uri = Uri.parse("http://www.example.com"); |
| 40 | + |
| 41 | + DynamicLink link = |
| 42 | + dl.createDynamicLink() |
| 43 | + .setLink(uri) |
| 44 | + .setDomainUriPrefix("http://example.page.link") |
| 45 | + .setAndroidParameters(new DynamicLink.AndroidParameters.Builder().build()) |
| 46 | + .buildDynamicLink(); |
| 47 | + Uri actual = link.getUri(); |
| 48 | + String[] query = actual.getQuery().split("&"); |
| 49 | + |
| 50 | + assertThat(actual.getScheme()).isEqualTo("http"); |
| 51 | + assertThat(actual.getHost()).isEqualTo("example.page.link"); |
| 52 | + assertThat(query) |
| 53 | + .asList() |
| 54 | + .containsAtLeast("apn=com.google.firebase.testing.combined", "link=http://www.example.com"); |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + public void getDynamicLink_NonLinkReturnsNull() throws Exception { |
| 59 | + FirebaseDynamicLinks dl = FirebaseDynamicLinks.getInstance(); |
| 60 | + Uri uri = Uri.parse("http://www.example.com"); |
| 61 | + |
| 62 | + Task<?> task = dl.getDynamicLink(uri); |
| 63 | + Object actual = Tasks2.waitForSuccess(task); |
| 64 | + |
| 65 | + assertThat(actual).isNull(); |
| 66 | + } |
| 67 | +} |
0 commit comments