• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.wallpaper.util
17 
18 import android.content.Intent
19 import android.net.Uri
20 import com.android.wallpaper.util.DeepLinkUtils.EXTRA_KEY_COLLECTION_ID
21 import com.google.common.truth.Truth.assertThat
22 import dagger.hilt.android.testing.HiltAndroidTest
23 import org.junit.Before
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.robolectric.RobolectricTestRunner
27 
28 @RunWith(RobolectricTestRunner::class)
29 @HiltAndroidTest
30 class DeepLinkUtilsTest {
31     private lateinit var intent: Intent
32 
33     @Before
setUpnull34     fun setUp() {
35         intent = Intent()
36     }
37 
38     @Test
testIsDeepLink_DeeplinkIntent_returnsTruenull39     fun testIsDeepLink_DeeplinkIntent_returnsTrue() {
40         intent.data = Uri.fromParts("https", "//g.co/wallpaper", "foo")
41         assertThat(DeepLinkUtils.isDeepLink(intent)).isTrue()
42     }
43 
44     @Test
testIsDeepLink_NoData_returnsFalsenull45     fun testIsDeepLink_NoData_returnsFalse() {
46         assertThat(DeepLinkUtils.isDeepLink(intent)).isFalse()
47     }
48 
49     @Test
testIsDeepLink_FakeDomainUri_returnsFalsenull50     fun testIsDeepLink_FakeDomainUri_returnsFalse() {
51         intent.data = Uri.fromParts("https", "//example.com", "foo")
52         assertThat(DeepLinkUtils.isDeepLink(intent)).isFalse()
53     }
54 
55     @Test
getCollectionId_FromUrinull56     fun getCollectionId_FromUri() {
57         val testCollection = "test_collection"
58         intent.data = Uri.parse("https://g.co/wallpaper?collection_id=$testCollection")
59         assertThat(DeepLinkUtils.getCollectionId(intent)).isEqualTo(testCollection)
60     }
61 
62     @Test
getCollectionId_FromExtranull63     fun getCollectionId_FromExtra() {
64         val testCollection = "test_collection"
65         intent.putExtra(EXTRA_KEY_COLLECTION_ID, testCollection)
66         assertThat(DeepLinkUtils.getCollectionId(intent)).isEqualTo(testCollection)
67     }
68 
69     @Test
getCollectionId_Emptynull70     fun getCollectionId_Empty() {
71         assertThat(DeepLinkUtils.getCollectionId(intent)).isNull()
72     }
73 }
74