@@ -19,13 +19,17 @@ import com.google.common.truth.Truth.assertThat
19
19
import com.google.firebase.FirebaseApp
20
20
import com.google.firebase.FirebaseOptions
21
21
import com.google.firebase.dynamiclinks.FirebaseDynamicLinks
22
+ import com.google.firebase.dynamiclinks.PendingDynamicLinkData
23
+ import com.google.firebase.dynamiclinks.ShortDynamicLink
22
24
import com.google.firebase.ktx.Firebase
23
25
import com.google.firebase.ktx.app
24
26
import com.google.firebase.ktx.initialize
25
27
import org.junit.After
26
28
import org.junit.Before
27
29
import org.junit.Test
28
30
import org.junit.runner.RunWith
31
+ import org.mockito.Mockito.`when`
32
+ import org.mockito.Mockito.mock
29
33
import org.robolectric.RobolectricTestRunner
30
34
import org.robolectric.RuntimeEnvironment
31
35
@@ -223,4 +227,45 @@ class DynamicLinksTests : BaseTestCase() {
223
227
val efr = Integer .parseInt(dynamicLink.uri.getQueryParameter(" efr" )!! ) == 1
224
228
assertThat(efr).isEqualTo(forcedRedirect)
225
229
}
230
+
231
+ @Test
232
+ fun `ShortDynamicLink destructure declaration works` () {
233
+ val fakeWarning = object : ShortDynamicLink .Warning {
234
+ override fun getMessage () = " Warning"
235
+ override fun getCode () = " warning"
236
+ }
237
+
238
+ val expectedShortLink = Uri .parse(" https://example.com" )
239
+ val expectedPreviewLink = Uri .parse(" https://example.com/preview" )
240
+ val expectedWarnings = mutableListOf<ShortDynamicLink .Warning >(fakeWarning)
241
+
242
+ val mockShortDynamicLink = mock(ShortDynamicLink ::class .java)
243
+ `when `(mockShortDynamicLink.shortLink).thenReturn(expectedShortLink)
244
+ `when `(mockShortDynamicLink.previewLink).thenReturn(expectedPreviewLink)
245
+ `when `(mockShortDynamicLink.warnings).thenReturn(expectedWarnings)
246
+
247
+ val (shortLink, previewLink, warnings) = mockShortDynamicLink
248
+
249
+ assertThat(shortLink).isEqualTo(expectedShortLink)
250
+ assertThat(previewLink).isEqualTo(expectedPreviewLink)
251
+ assertThat(warnings).isEqualTo(expectedWarnings)
252
+ }
253
+
254
+ @Test
255
+ fun `PendingDynamicLinkData destructure declaration works` () {
256
+ val expectedLink = Uri .parse(" https://example.com" )
257
+ val expectedMinAppVersion = 30
258
+ val expectedTimestamp = 172947600L
259
+
260
+ val mockPendingData = mock(PendingDynamicLinkData ::class .java)
261
+ `when `(mockPendingData.link).thenReturn(expectedLink)
262
+ `when `(mockPendingData.minimumAppVersion).thenReturn(expectedMinAppVersion)
263
+ `when `(mockPendingData.clickTimestamp).thenReturn(expectedTimestamp)
264
+
265
+ val (link, minAppVersion, timestamp) = mockPendingData
266
+
267
+ assertThat(link).isEqualTo(expectedLink)
268
+ assertThat(minAppVersion).isEqualTo(expectedMinAppVersion)
269
+ assertThat(timestamp).isEqualTo(expectedTimestamp)
270
+ }
226
271
}
0 commit comments